
Шифр цезаря на паскале , почему не выдает при дешифрации букву В с ключом 3 и 5 и дальше!что
исправить? program SHIFR_CEZERYA; uses crt; var a,b,c:string; i,j,k,d,g:integer;begin clrscr; writeln('Шифрование?1-да,0-нет'); readln(g); writeln('Исходный текст '); readln(a); writeln('ключ'); readln(d); c:=''; //Результат b:='абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; for i:=1 to length(a) do //цикл for j:=1 to length(b) do begin If g=1 then k:=(j+d) mod 33 else k:=(j-d)mod 33; if a[i]=b[j] then c:=c+b[k]; If k>33 then k:=k-33 else k:=k+33; end; writeln(c); readkey; end.

Ответы на вопрос

2. Отладка в этом случае должна помоч. Вводи алфавит и смотри результат, должен быть сдвиг на ключ.



The Caesar cipher is a simple substitution cipher that shifts the letters of the alphabet by a certain number of positions. In the provided Pascal code, there seems to be an issue with the decryption process where the letter 'В' (which corresponds to the Latin letter 'B') is not being correctly decrypted when using key values of 3 and 5.
To understand the issue and suggest a fix, let's analyze the code snippet:
```pascal program SHIFR_CEZERYA; uses crt; var a, b, c: string; i, j, k, d, g: integer; begin clrscr; writeln('Шифрование? 1-да, 0-нет'); readln(g); writeln('Исходный текст'); readln(a); writeln('Ключ'); readln(d); c := ''; b := 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; for i := 1 to length(a) do begin for j := 1 to length(b) do begin if g = 1 then k := (j + d) mod 33 else k := (j - d) mod 33; if a[i] = b[j] then c := c + b[k]; if k > 33 then k := k - 33 else k := k + 33; end; end; writeln(c); readkey; end. ```
The issue lies in the line `if a[i] = b[j] then c := c + b[k];`. The decryption process should be performed after the inner loop, not within it. This is causing incorrect decryption results.
To fix this issue, move the decryption process outside the inner loop. Here's the modified code:
```pascal program SHIFR_CEZERYA; uses crt; var a, b, c: string; i, j, k, d, g: integer; begin clrscr; writeln('Шифрование? 1-да, 0-нет'); readln(g); writeln('Исходный текст'); readln(a); writeln('Ключ'); readln(d); c := ''; b := 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; for i := 1 to length(a) do begin for j := 1 to length(b) do begin if g = 1 then k := (j + d) mod 33 else k := (j - d) mod 33; if a[i] = b[j] then c := c + b[j]; end; if k > 33 then k := k - 33 else k := k + 33; end; writeln(c); readkey; end. ```
With this modification, the decryption process will be performed correctly, and the letter 'В' (Latin 'B') should be decrypted as expected when using key values of 3 and 5.
Please note that this fix assumes that the provided code is intended to work with the Russian alphabet, as indicated by the string `b := 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';`. If you intend to use a different alphabet, you will need to modify the `b` string accordingly.
I hope this helps! Let me know if you have any further questions.


Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili