ممنون این لینک رو خونده بودم!!
همون طور که گفتم میخواستم ببینم چجوری پیاده سازی میشه که
حل شد.
این مثال رو هم میزارم برای کسهایی که بعداً شاید احتیاج داشته باشن:
Written in C
/*
* This Application is for Solving 3rd part of assignment -- Crack Cipher using Vernam Encryption
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
FILE *cipherFile,*padFile;
char buf;
int byte1,byte2;
if(argc != 3){
fprintf(stderr,"Usage: %s <Cipher File> <Pad File>\n",argv[0]);
return 1;
}
if((cipherFile=fopen(argv[1],"r")) ==NULL){
fprintf(stderr,"[!]Cannot Open Cipher File.\n");
return 1;
}
printf("[+]Reading Cipher File: %s\n",argv[1]);
if((padFile = fopen(argv[2],"r")) == NULL){
fprintf(stderr,"[!]Cannot Open Pad File.\n");
return 0;
}
printf("[+]Reading Pad File: %s\n",argv[2]);
printf("[+]Decrypted Message is: \"");
while (byte1 != EOF)
{
byte1 = fgetc(cipherFile);
byte2 = fgetc(padFile);
//buf = byte1 ^ byte2;
if(byte1 == EOF) break;
// printf("Byte in hex: 0x%x\n",byte1);
buf = byte1 ^ byte2;
printf("%c",buf);
}
printf("\"\n[-]Program Terminating...\n");
fclose(cipherFile);
fclose(padFile);
return 0;
}
فایل Pad و Encrypt شد رو هم Attach کردم