How to decrypt text with a given key using arrays? (In C ++, 2nd month)

I'm thinking about creating two arrays: one cipher, the other key. And replace the first with the second. But the trouble is, I can not take and replace one Cyrillic with another. + Does not read Cyrillic at all and hieroglyphs are displayed in the command line.

  • Generally nothing is clear. At least which cipher is a direct substitution, the replacement of one alphabet by another? - gbg
  • To decipher the text: "Ruintsekevfekekestfaitapmsiusprym. MfhftmfOfndi." Open text: "Afgoepruzv". Symbols of the ciphered text: "fgopozruzva". - Shurik Anvarov
  • Key, encryption algorithm - known? - gbg
  • The principle of an eye for an eye will keep the whole world blind. Mahatma Gandi - is that enough? :) - Harry
  • @gdb Yes, he has a problem in Cyrillic; There's nothing to decipher ... - Harry

2 answers 2

Here is your transcript:

char text[] = "руинцирекевфекеестфаитапсьмиуслпрым. мфхфтмфофнди"; char src[] = "афгоепрузв"; char dst[] = "фгоепрузва"; int main(int argc, const char * argv[]) { for(char * c = text; *c; ++c) { char * s = strchr(dst,*c); if (s) *c = src[s-dst]; cout << *c; } } 

To quickly, I

  1. Wrote in 866 encoding and did not bother with Russian letters.

  2. hands converted all characters to lower case.

The principle is ridiculously simple - if the letter of a long text is in an encrypted text ("fgapruzva") - we change it to the corresponding letter of the plaintext; if not, leave the letter as it is ...

  • Yes, such an algorithm immediately came to mind when I first met the task, but did not know how to implement it. char * c / s - are these pointers or some operators used specifically for char types? - Shurik Anvarov
  • Pointers to char - Harry

If there are hieroglyphs in the command line, then the command line and file encoding are most likely different. If you're on Linux, use utf-8