#include const string perm = "kjtembvwgcnqzalphyfoxurdis "; const string alph = "abcdefghijklmnopqrstuvwxyz "; int find(char c, string s, int pos) { if (pos >= s.length()) return -1; else if (s[pos] == c) return pos; else return find(c, s, pos + 1); } void translate(string text, string p, string a, int pos) { // print("pos = "); print(pos); new_line(); // print("text = "); print(text); new_line(); // print("text.length() = "); print((int)text.length()); new_line(); if (pos >= text.length()) { new_line(); return; } const int where = find(text[pos], p, 0); if (where == -1) print("?"); else print(a[where]); translate(text, p, a, pos + 1); } void main() { print("encrypt (1) or decrypt (2) ? "); const int eord = read_int(); read_line(); // to consume the \n I typed print("enter a line: "); const string text = read_line(); if (eord == 1) translate(text, perm, alph, 0); else translate(text, alph, perm, 0); }