Skip to content

Instantly share code, notes, and snippets.

@nuit
Created April 10, 2015 16:10
Show Gist options
  • Save nuit/4402d4e0171d4f3e5c46 to your computer and use it in GitHub Desktop.
Save nuit/4402d4e0171d4f3e5c46 to your computer and use it in GitHub Desktop.
vernam
#include <stdio.h>
int main(){
int M,m;
int ch,k,r;
ch=getchar();
//ascii >> A=65,a=97 e Z=90,z=122
for (M=65, m=97;(M<=90) && (m<=122);M++, m++){
while ((ch=getchar()) != EOF){
r=rand()%26;
if ((ch>='A') && (ch<='Z')){
k=ch+r;
putchar((ch-'A'+k)%26+'A');
}
else if ((ch>='a') && (ch<='z')){
k=ch+r;
putchar((ch-'a'+k)%26+'a');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment