2013-03-21 160 views
2

我在互联网上发现了很多例子,但是找不到土耳其字母表的Ceaser密码解密。大多数的字母类似英文字母,但也有一些区别 这里是土耳其字母:土耳其字母表的凯撒密码解密

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

我发现英文字母的代码,它并没有一些字母像I,O,U,S,C,G,I,O,S,U:

#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; 
} 

请帮我做这个工作,为土耳其字母表。

+0

你有什么试过?你对你发布的代码有什么不了解?请更具体一些。 – RedX 2013-03-21 13:21:57

+0

因为其中一些字符不是ASCII字符编码的一部分,所以首先需要使用比char更广泛的数据类型。您也不能简单地添加移位值,因为这将导致字符不是您的字母表的一部分 – msam 2013-03-21 13:27:50

+0

我无法使用这些字母时,使用这些字母时,使加密或解密,例如,如果我移动1个字母“İ”与解密我应该有“我”为Turkhis字母表,但代码给“h”。我不知道也许是因为它的ASCII码,但我不知道如何为这段代码隐藏这些字母。 – thomas123 2013-03-21 13:28:45

回答

4

您发布的示例代码依赖于标准拉丁字母表是ASCII表中的连续块的事实。对于土耳其语字母表而言,情况并非如此,因此您必须以不同的方式处理问题。

我建议你使用替换表。创建一个由256个字符组成的数组(字符编码表中的每个代码点都有一个字符),并用应该使用的字母填充每个代码点,而不是使用它。然后迭代输入文本并通过在该数组中查找来替换每个字符。

+0

好的,谢谢,我会尝试。 – thomas123 2013-03-21 13:37:33

+0

我尝试了一些数组,但现在还不知道。假设我们有“c”,“ç”和解密,我怎样才能得到“b”,“c”(只有1个移位c,ç到b,c的英文顺序是b,c在turkıshc,ç)if你很容易能给我一个线索。 – thomas123 2013-03-21 15:23:18

+0

@ thomas123对不起,但我不明白你的问题。 – Philipp 2013-03-21 17:12:02