Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void Left(char* cipher){
- char variable;
- int len = strlen(cipher);
- variable = cipher[0];
- int a = 0;
- for(a=0; a < len; a++){
- cipher[a]=cipher[a+1];
- }
- cipher[len - 1] = variable;
- }
- void Right(char* cipher){
- char newVariable;
- int len = strlen(cipher);
- newVariable = cipher[len - 1];
- int a = 0;
- for(a=len-1; a > 0; a--){
- cipher[a]=cipher[a-1];
- }
- cipher[0] = newVariable;
- }
- void Increment(char* cipher){
- int len = strlen(cipher);
- char hold;
- int i = 0;
- while(i < len){
- hold = cipher[i];
- if (hold >= 'a' && hold < 'z'){
- hold = hold + 1;
- }
- else if (hold >= 'A' && hold < 'Z'){
- hold = hold + 1;
- }
- else if (hold == 'z'){
- hold = 'a';
- }
- else if (hold == 'Z'){
- hold = 'A';
- }
- else if (hold >= '0' && hold < '9'){
- hold++;
- }
- else if (hold == '9'){
- hold = '0';
- }
- i++;
- cipher[i] = hold;
- }
- }
- void Decrement(char* cipher){
- int len = strlen(cipher);
- char hold;
- int i = 0;
- while(i<len){
- hold = cipher[i];
- if (hold > 'a' && hold <= 'z'){
- hold = hold - 1;
- }
- else if (hold > 'A' && hold <= 'Z'){
- hold = hold - 1;
- }
- else if (hold == 'a'){
- hold = 'z';
- }
- else if (hold == 'A'){
- hold = 'Z';
- }
- else if (hold > '0' && hold <= '9'){
- hold--;
- }
- else if (hold == '0'){
- hold = '9';
- }
- i++;
- cipher[i] = hold;
- }
- }
- int main(int argc, char** argv){
- FILE* f1 = NULL;
- char commands[100] = " ";
- int i = 0;
- int a = 0;
- f1 = fopen(argv[1], "r");
- fscanf(f1, "%s", commands);
- if (f1 == NULL){
- printf("No File Found");
- }
- while(!feof(f1)){
- for (a=2; a < argc; a++){
- for (i=0; i < strlen(argv[a]); i++){
- if (argv[a][i] == 'L'){
- Left(commands);
- }
- else if (argv[a][i] == 'R'){
- Right(commands);
- }
- else if (argv[a][i] == 'I'){
- Increment(commands);
- }
- else if (argv[a][i] == 'D'){
- Decrement(commands);
- }
- else {
- printf("No valid cipher command");
- }
- }
- }
- printf("%s\n", commands);
- fscanf(f1, "%s", commands);
- }
- fclose(f1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement