錯信你好,我有關於凱撒密碼例如C++輸出
主要新問題:3
平原:ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ
密碼:DEFGĞHIİJKLMNOÖPRSŞTUÜVYZABCD
這些都是土耳其的字母「C, 「
我需要做加密和解密,並且p程序不應區分大小寫。它應該像S = S,C = C
下面你可以看到我的節目,但我有一些問題
1)文本(平原)和密鑰應該由用戶輸入的,但我不可能做到這一點。 2)char text [] =「DEF」;該輸入應該給(用於解密)「CCD」,但它給「CAD」
通常也應該給「C」,而不是「A」
我需要幫助:(
# include <iostream>
# include <cstring>
const char alphabet[] ={'A', 'B', 'C', 'Ç', 'D', 'E', 'F', 'G', 'Ğ', 'H', 'I',
'İ', 'J', 'K', 'L', 'M', 'N', 'O', 'Ö', 'P', 'R', 'S',
'Ş', 'T', 'U', 'Ü', 'V', 'Y', 'Z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '.', ',', ':', ';', ' '};
const int char_num =44;
void cipher(char word[], int count, int key)
{
int i = 0;
while(i < count) {
int ind = -1;
while(alphabet[++ind] != word[i]) ;
ind += key;
if(ind >= char_num)
ind -= char_num;
word[i] = alphabet[ind];
++i;
}
}
void decipher(char word[], int count, int key)
{
int i = 0;
while(i < count) {
int ind = -1;
while(alphabet[++ind] != word[i]) ;
ind -= key;
if(ind < 0)
ind += char_num;
word[i] = alphabet[ind];
++i;
}
}
int main()
{
char text[] = "ABC";
int len = strlen(text);
std::cout << text << std::endl;
cipher(text, len, 2);
std::cout << text << std::endl;
decipher(text, len, 2);
std::cout << text << std::endl;
system("pause");
return 0;
}
「1)文本和密鑰應該由用戶輸入,但我發現它,因爲我一直給出錯誤」< - 這不是一個有用的描述你的問題。 – us2012 2013-03-22 17:08:33
[絕對最低限度每個軟件開發人員絕對,肯定必須知道Unicode和字符集(沒有藉口!)](http://www.joelonsoftware.com/articles/Unicode.html) – 2013-03-22 17:13:12
問題不在於代碼。這是您要打印的控制檯尚未設置爲處理Unicode字符。 Ç的Unicode值爲199,但在DOS 199中打印爲Ã。 – john 2013-03-22 17:16:14