Advertisement
e55db081d05f58a

cesar.c

Apr 1st, 2021 (edited)
1,774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.97 KB | None | 0 0
  1. /*
  2.  *With L0v3 from @ov3rflow1 :P
  3.  * */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. void cesar();
  7. int selection();
  8. char * readBuffer();
  9. int main(int argc,char **argv){
  10.     cesar();
  11.     return 0x00;
  12. }
  13.  
  14. void cesar(){
  15.     char *password,*buffer=NULL;
  16.     int i,keySum,action=0;
  17.  
  18.     printf("==ALGORITMO DE C3$4r==\n\n");
  19.     action=selection();
  20.    
  21.     printf("\nBuffer:");
  22.     buffer=readBuffer();
  23.     printf("\nPassword: ");
  24.     password=readBuffer();
  25.  
  26.     i=0;
  27.     keySum=0;
  28.    
  29.     while((int)*(password+i)!=0){
  30.         keySum+=(int)(*(password+i));
  31.         i++;
  32.     }
  33.     keySum*=action;
  34.         printf("Procediendo con el desplazamiento:%d\n",keySum);   
  35.     i=0;
  36.     while((int)*(buffer+i)!=0){
  37.         char tmp=((int)*(buffer+i))+keySum;
  38.         printf("%c",tmp);
  39.         i++;
  40.     }
  41. }
  42. /*
  43. int selection(){
  44.     int action=0;
  45.     printf("Menu de opciones:\n\n");
  46.     printf("\t1) cifrar\n");
  47.     printf("\t2) descifrar\n");
  48.     printf("\nElige una opcion: ");
  49.     scanf("%d",&action);
  50.     switch(action){
  51.         case 1:
  52.             action=1;
  53.             break;
  54.         case 2:
  55.             action=-1;
  56.             break;
  57.         default:
  58.             action=1;
  59.     }
  60.     return action;
  61. }
  62. */
  63.  
  64. int selection(){
  65.     char *buffer;
  66.     printf("Menu de opciones:\n\n");
  67.     printf("\t1) cifrar\n");
  68.     printf("\t2) descifrar\n");
  69.     printf("\nElige una opcion: ");
  70.     buffer=readBuffer();
  71.     switch(*(buffer+0)){
  72.         case '1':
  73.             return 1;
  74.         case '2':
  75.             return -1;
  76.         default:
  77.             return 1;
  78.     }
  79. }
  80.  
  81. /*
  82. char * readBuffer(){
  83.     char **ptrStr=malloc(sizeof(char*)*1);
  84.     char key;
  85.     int len=0;
  86.     *(ptrStr+0)=malloc(sizeof(char));
  87.     char pacman;
  88.     scanf("%c",&pacman);
  89.     if((int)pacman!=10)
  90.         key=pacman;
  91.     else
  92.         scanf("%c",&key);
  93.     while((int)key!=10){
  94.         *(*(ptrStr+0)+len)=key;
  95.         scanf("%c",&key);
  96.         len++;
  97.     }
  98.     char *retStr=*(ptrStr+0);
  99.     return retStr;
  100. }
  101. char *readBuffer(){
  102.     char pacman;
  103.     char *buffer;
  104.     scanf("%c",&pacman);
  105.     buffer=malloc(sizeof(char)*31337);
  106.     //scanf("%s",buffer);
  107.     gets(buffer);
  108.     return buffer;
  109. }
  110. */
  111. char *readBuffer(){
  112.     char *buffer;
  113.     buffer=malloc(sizeof(char)*31337);
  114.     gets(buffer);
  115.     return buffer;
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement