Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void Left(char* cipher){
  6.   char variable;
  7.   int len = strlen(cipher);
  8.   variable = cipher[0];
  9.   int a = 0;
  10.   for(a=0; a < len; a++){
  11.     cipher[a]=cipher[a+1];
  12.   }
  13.   cipher[len - 1] = variable;
  14. }
  15.  
  16. void Right(char* cipher){
  17.   char newVariable;
  18.   int len = strlen(cipher);
  19.   newVariable = cipher[len - 1];
  20.   int a = 0;
  21.   for(a=len-1; a > 0; a--){
  22.     cipher[a]=cipher[a-1];
  23.   }
  24.   cipher[0] = newVariable;
  25. }
  26.  
  27. void Increment(char* cipher){
  28.   int len = strlen(cipher);
  29.     char hold;
  30.     int i = 0;
  31.     while(i < len){
  32.     hold = cipher[i];
  33.     if (hold >= 'a' && hold < 'z'){
  34.       hold = hold + 1;
  35.     }
  36.     else if (hold >= 'A' && hold < 'Z'){
  37.       hold = hold + 1;
  38.     }
  39.     else if (hold == 'z'){
  40.       hold = 'a';
  41.     }
  42.     else if (hold == 'Z'){
  43.       hold = 'A';
  44.     }
  45.     else if (hold >= '0' && hold < '9'){
  46.       hold++;
  47.     }
  48.     else if (hold == '9'){
  49.       hold = '0';
  50.     }
  51.     i++;
  52.     cipher[i] = hold;
  53. }
  54. }
  55.  
  56. void Decrement(char* cipher){
  57.   int len = strlen(cipher);
  58.   char hold;
  59.   int i = 0;
  60.   while(i<len){
  61.   hold = cipher[i];
  62.   if (hold > 'a' && hold <= 'z'){
  63.     hold = hold - 1;
  64.   }
  65.   else if (hold > 'A' && hold <= 'Z'){
  66.     hold = hold - 1;
  67.   }
  68.   else if (hold == 'a'){
  69.     hold = 'z';
  70.   }
  71.   else if (hold == 'A'){
  72.     hold = 'Z';
  73.   }
  74.   else if (hold > '0' && hold <= '9'){
  75.     hold--;
  76.   }
  77.   else if (hold == '0'){
  78.     hold = '9';
  79.   }
  80.   i++;
  81.   cipher[i] = hold;
  82. }
  83. }
  84.  
  85.  
  86. int main(int argc, char** argv){
  87.   FILE* f1 = NULL;
  88.   char commands[100] = " ";
  89.   int i = 0;
  90.   int a = 0;
  91.  
  92. f1 = fopen(argv[1], "r");
  93. fscanf(f1, "%s", commands);
  94.  
  95. if (f1 == NULL){
  96.   printf("No File Found");
  97. }
  98. while(!feof(f1)){
  99. for (a=2; a < argc; a++){
  100.  for (i=0; i < strlen(argv[a]); i++){
  101.    if (argv[a][i] == 'L'){
  102.      Left(commands);
  103.    }
  104.    else if (argv[a][i] == 'R'){
  105.      Right(commands);
  106.    }
  107.    else if (argv[a][i] == 'I'){
  108.      Increment(commands);
  109.    }
  110.    else if (argv[a][i] == 'D'){
  111.      Decrement(commands);
  112.    }
  113.    else {
  114.      printf("No valid cipher command");
  115.    }
  116.   }
  117.  }
  118.  printf("%s\n", commands);
  119.  fscanf(f1, "%s", commands);
  120.  }
  121. fclose(f1);
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement