Skip to content

Instantly share code, notes, and snippets.

@perilstar
Created September 1, 2017 13:02
Show Gist options
  • Save perilstar/6b0a90ba17a59930ad50a729cc0ada8f to your computer and use it in GitHub Desktop.
Save perilstar/6b0a90ba17a59930ad50a729cc0ada8f to your computer and use it in GitHub Desktop.
Encrypty thing created by ekyl - https://repl.it/K9KG/3
#include<iostream>
using namespace std;
char encryptChar(char c, int key) {
key %= 52
if (c < 65 || (c > 90 && c < 97) || c > 122) { // don't encrypt non-letters
return c;
}
if (65 <= c && c <= 90 && c+key>90) { // handling the middle bit
c += 7;
key -= 1;
}
c += key;
return (c - 65) % 58 + 65; //handling the edge bit
}
char decryptChar(char c, int key) {
key %= 52
if (c < 65 || (c > 90 && c < 97) || c > 122) { // don't attempt to decrypt non-letters
return c;
}
if (97 <= c && c <= 122 && c-key<97) { // middle bit again
c -= 7;
key -= 1;
}
c -= key;
if (c < 65) { //handling the other edge bit
c += 58;
}
return c;
}
string encryptString(string s, int key) {
string o = "";
for (int i = 0; i < s.size(); i++) {
o+=encryptChar(s[i],key);
}
return o;
}
string decryptString(string s, int key) {
string o = "";
for (int i = 0; i < s.size(); i++) {
o+=decryptChar(s[i],key);
}
return o;
}
int main() {
string in = "DANK MEMES AMIRITE and some lowercase yeet azAZ";
string encrypted = encryptString(in,1);
cout << encrypted << endl;
string decrypted = decryptString(encrypted,1);
cout << decrypted << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment