Hi guys, I am new to this forum and C programming language.
Currently, I am doing an application and faced with some problems.
Hope you guys here can help!!!
I am doing an application on cryptography.
Basically what the program does is to read in ciphertexts(encrypted texts).
The texts will then be decrypt with a key to generate out the plain english texts.
My program should decrypt letters(a,b,c,...,z) of the ciphertext leaving the others characters(1234567890.,!@#$~%^&<>"space") unaltered. Unaltered characters will not advance the shift to its
next key.
E.g. ciphertext: "sgdty &hy, GHYTR?" decrypt with the key "boy" should decrypt using this method
"boybo &yb, OYBOY?" and
NOT to "boybo &oy, YBOYB?"
Currently, my program is able to leave the unaltered characters unchanged. The nummbers, !@#$%^ even "space" seems to work fine. However, all my alphabets(a-z) after going through the algorithmn display out texts that is not plain english texts.
Below is a portion of my source code that i used to decrypt the ciphertext to english text.
Code:
char *vig_dec_str(char *str, char *key)
{
int ii, key_len = strlen(key);
if(key_len < 1) { vig_error(VIG_ELENGTH); }
#define VIG_DEC_CHAR(C, K) (K == '-') ? ' ' : \
('A' + (26 + (C - 'A') - (K - 'A')) % 26)
for(ii = 0; str[ii]; ii++)
{
if(isalpha(str[ii]))
{
str[ii] = VIG_DEC_CHAR(str[ii], key[ii % key_len]);
}
else if(isdigit(str[ii]))
{
str[ii] = str[ii];
}
else if(ispunct(str[ii]))
{
str[ii] = str[ii];
}
else if(iscntrl(str[ii]))
{
str[ii] = str[ii];
}
putchar(str[ii]);
}
return str;
}
I believe the problem is because my source code decrypt the texts using this method "boybo &oy, YBOYB?" which is wrong. I would like my program to decrypt the texts using this method "boybo &yb, OYBOY?".
One of the methods that i try is removing all numbers, !@#$%^, and "space" from the ciphertexts combine the whole string texts and do the decryption. This method is not good because I am able to
decrypt the texts correctly but i lose all my spacing, numbers and !@#$%.
E.g.
Results using this method: IneedsomehelpfromMrcanyouhelpmePlease
Actual text message: I need some help from Mr.123 can you help me? Please!
Hope you guys can help me out!
Thanks in advance.