土耳其字母表的凯撒密码解密

Caesar cipher decryption for Turkish alphabet's

本文关键字:密码 解密 凯撒 字母表 土耳其      更新时间:2023-10-16

我在网上找到了很多例子,但找不到土耳其字母的凯撒密码解密。大多数字母与英语字母表相似,但也有一些不同以下是土耳其字母:

A B C Ç D E F G Ğ H I İ J K L M N O Ö P R S Ş T U Ü V Y Z

a b c ç d e f g ğ h i ı j k l m n o ö p r s ş t u ü v y z

我找到了这个英文字母代码,它没有一些字母,如İ,Ö,Ü,Ş,ç, erdogan, yi,ö,

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int main()
{
    char code[501];
    int shift, len, i=0, j=0;
    cout << "Caesar Cipher Decoder " << endl;
    cout << "nThis program will decrypt the entered text using Caesar Cipher." << endl;
    cout << "nPress any key to continue...";
    _getch();
    system("cls");
    cout << "Enter the text that has to be decrypted (max 500 characters):" << endl;
    cin.getline(code, 501);
    len = strlen(code);
    while (j < len)
    {
        if(code[j] == 32)
        {
            code[j] = code[j];
        }
        j++;
    }
    po:
    cout << "nEnter the amount of Caseser Shift in numbers: ";
    cin >> shift;
    if ((shift > 26) || (shift < 0))
    {
        cout << "nShift value should be less than or equal to 26. Type again." << endl;
        goto po;
    }
    while (i < len)
    {
        code[i] = tolower(code[i]);
        code[i] = code[i] - shift;
        if (code[i] + shift == 32)
        {
            code[i] = code[i] + shift;
        }
        else if(
                ((code[i] + shift > 31) && (code[i] + shift < 65)
                || ((code[i] + shift > 90) && (code[i] + shift < 97))
                || ((code[i] + shift > 122) && (code[i] + shift < 128)))
                )
                {
                    code[i] = code[i] + shift;
                }
        else if (code[i] < 97)
        {
            if (code[i] == 32 - shift)
            {
                code[i] = code[i] + shift;
            }
            else
            {
                code[i] = (code[i] + 26);
            }
        }
        i++;
    }
    system("cls");
    cout << "nYour deciphered code is: "" << code << """ << endl;
    cout << "nYour text has been decrypted." << endl;
    cout << "nPress any key to end." << endl;
    _getch();
    return 0;
}

请帮我把这个工作为土耳其字母

您发布的示例代码依赖于标准拉丁字母是ASCII表中连续块的事实。但土耳其字母不是这样的,所以你必须用不同的方法来解决这个问题。

我建议您使用替换表。创建一个包含256个字符的数组(字符编码表中的每个代码点对应一个字符),并用应该使用的字母填充每个代码点。然后迭代输入文本并通过在该数组中查找来替换每个字符。