One Time Pad

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include "stdio.h" #include "stdlib.h" #include "string.

h" #define DEFAULT_KEYLEN 10 int memxor(char *a, char *b, int len){ int i; for(i=0;i<len;i++)a[i]^=b[i]; } int main(int argc, char **argv){ int keylen=DEFAULT_KEYLEN; if(argc < 2){ fputs("You have to give a key file!\n",stderr); return 1; } if(argc >= 3)sscanf(argv[2],"%d",&keylen); else fputs("Taking default key length of 10\n",stderr); char *key=malloc(keylen); FILE *keyf=fopen(argv[1],"r"); fread(key,1,keylen,keyf); fclose(keyf); int i=keylen; char *buf=malloc(keylen); int j=0; while(i==keylen){ i=fread(buf,1,keylen,stdin); memxor(buf,key,i); fwrite(buf,1,i,stdout); if(j++==1 && i) fputs("Be advised that this encryption is only " "completely secure if the key is at least as long as the text.\n ",stderr); } return 0; }

You might also like