PDA

View Full Version : Encryptor/decrypter



Ashur2Good
06-13-2011, 10:27 AM
Problem:

Need to design a program that can encrypt and decrypt messages stored in simple text files using a private key stored in a separate file. Software should also be able to allow the users to enter simple messages that either displays the encrypted or decrypted message. The encryption method should use a simple substitution method. It should be set out in the following format:

Example (the "@" is the separator):
@
The character The Code End of line
A @ 4gh EOL
B @ 84!9 EOL

Has to use the 256 ASCII character codes. The separator will be used to separate the character and its corresponding code.

Here are the pseudocodes I have come up with:


• Read any private key file

separator = readline(file);
while not EOF(file) do
tempStr = readline(file);
tempArr = split(separator, tempStr);
matchArr += tempArr[0];
substitutionArr += tempArr[1];
endwhile;
• Allow users to enter messages (by entering text or file)

string1 = user input from textbox

• Encrypt and decrypt messages
Encrypting:

string1: get input from other module;
length: length of string1;
While Counter < length do;
string2 += substitute from subarray(character(counter) of string1)
endwhille;
Decrypting:

string1 = get input from other module;
Length = length of string1;
while counter < length do;
string2 += substitute from matcharray(character(counter) of string1)
endwhile;
• Display encrypted/decrypted message

textbox = string1
• Print encrypted/decrypted message

print encrypt (string1);
print decrypt (string1);

Can anyone point out if anything wont work/any fixes.

Cheers
-Ashur

jerryt
06-13-2011, 08:39 PM
You are using the 256-ASCII characters so you would need to read the file as binary.

What is the encrypted message suppose to look like? I see that you have different substitute lengths for each letter; 'A' is three characters long, and 'B' is four characters long. Will there be spaces in the message to denote a different character?