Вопрос задан 09.05.2019 в 08:17. Предмет Информатика. Спрашивает Кузнецова Юля.

Шифр цезаря на паскале , почему не выдает при дешифрации букву В с ключом 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.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Коржаков Женя.
1. На кой такие сложности не ясно. Коды символов идут по порядку русских на сколько я помню,
2. Отладка в этом случае должна помоч. Вводи алфавит и смотри результат, должен быть сдвиг на ключ.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

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

Последние заданные вопросы в категории Информатика

Задать вопрос