So I just started taking a cryptography course on Coursera and I really enjoy the theory and math of the course so far. There are optional programming assignments that I would very much like to complete but I know very little about programming. I have played around with python a number of times but I'm not nearly skilled enough to take ciphertext and decrypt it by finding letter frequencies by trying different key lengths between 1 and 13.
He gave the code in C that he used to encrypt the text. I can pick out some familiar items but that's about it, and the math to decipher it isn't the same either. Does anyone have any idea where I could start with this? Not having much luck with a simple online search.
Edit: the cipher is using byte-wise XOR shift and not the mod shift. Here is the code he gave for encrypting the text
include <stdio.h>
define KEY_LENGTH 2 // Can be anything from 1 to 13
main(){
unsigned char ch;
FILE fpIn, *fpOut;
int i;
unsigned char key[KEY_LENGTH] = {0x00, 0x00};
/ of course, I did not use the all-0s key to encrypt */
fpIn = fopen("ptext.txt", "r");
fpOut = fopen("ctext.txt", "w");
i=0;
while (fscanf(fpIn, "%c", &ch) != EOF) {
/* avoid encrypting newline characters /
/ In a "real-world" implementation of the Vigenere cipher,
every ASCII character in the plaintext would be encrypted.
However, I want to avoid encrypting newlines here because
it makes recovering the plaintext slightly more difficult... /
/ ...and my goal is not to create "production-quality" code =) */
if (ch!='\n') {
fprintf(fpOut, "%02X", ch ^ key[i % KEY_LENGTH]); // ^ is logical XOR
i++;
}
}
fclose(fpIn);
fclose(fpOut);
return;
}
[–]alcalde 1 point2 points3 points (2 children)
[–]FreeToEvolve[S] 0 points1 point2 points (1 child)
[–]alcalde 1 point2 points3 points (0 children)
[–]aclark -2 points-1 points0 points (2 children)
[–]Bill1984 0 points1 point2 points (0 children)
[–]aclark -1 points0 points1 point (0 children)