Created
November 1, 2018 18:18
-
-
Save junaidrahim/d69b581d813cc05885556252c3bb92c8 to your computer and use it in GitHub Desktop.
Simple Atbash Encryptor in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
char atbash_encrypt(char input){ | |
if(input == ' '){ | |
return ' '; | |
} | |
char small_letters[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; | |
char capital_letters[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; | |
for(int i=0; i<26; i++){ | |
if(small_letters[i]==input){ | |
return small_letters[25-i]; | |
} | |
else if(capital_letters[i]==input){ | |
return capital_letters[25-i]; | |
} | |
} | |
return input; // for the case that input is anything else | |
} | |
char* atbash_convert_string(char* s){ | |
char* final_string = malloc(sizeof(char) * strlen(s));; | |
for(int i=0; i<strlen(s); i++){ | |
*(final_string+i) = atbash_encrypt(*(s+i)); | |
} | |
return final_string; | |
} | |
void main(){ | |
// Works both ways, enter original or encrypted text, it will give the opposite | |
char* input; | |
printf("Enter Text: "); | |
scanf("%[^\n]s",input); // wont break until a new line | |
char* encrypted_text = atbash_convert_string(input); | |
printf("\nEncrypted Text is: %s\n",encrypted_text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment