凱撒密碼使用用戶定義的密鑰和文本加密文本。我的凱撒密碼版本有什麼問題? pset 2
在密碼學中,凱撒密碼也被稱爲凱撒密碼,密碼轉換,凱撒代碼或凱撒轉換,是最簡單和最廣爲人知的加密技術之一。它是一種替代密碼,其中明文中的每個字母被一個字母替換爲一個固定數量的字母。例如,如果左移3,則D將被替換爲A,E將變爲B,等等。該方法是凱撒,誰在他的私人信件用它
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
int main (int argc , string argv[])
{
int key,save;
string s ;
key = atoi(argv[1]);
s = GetString();
if ( argc != 2)
{
printf("prgram is yelling at you !!");
return 1 ;
}
for (int i = 0 ; s[i]!='\0' ; ++i) // manipulation without storing character
{
if (isalpha(s[i])) // checks whether input is in character set or not
{
if (islower (s[i])) // FOR LOWER CASES
{
save = key % 24 ;
s[i] = s[i] + save ;
if (s[i] > 'z')
s[i] = 'a' + (s[i] - 'z' -1);
}
if (isupper (s[i])) // FOR UPPER CASES
{
save = key % 24 ;
s[i] = s[i] + save ;
if (s[i] > 'Z')
s[i] = 'A' + (s[i] - 'Z' -1);
}
}
printf ("%c" , s[i]);
}
return 0 ;
}
事實而得名:
:) caesar.c exists
:) caesar.c compiles
:(encrypts "a" as "b" using 1 a s key
\ expected output, but not "b"
:(encrypts "barfoo" as "yxocll" using 23 as key
\ expected output, but not "yxc"
:(encrypts "BARFOO" as "EDUIRR" using 3 as key
\ expected output, but not "EDUIRR"
:(encrypts "BaRFoo" as "FeVJss" using 4 as key
\ expected output, but not "FeVJss"
:(encrypts "barfoo" as "onesbb" using 65 as key
\ expected output, but not "srw"
:(encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
\ expected output, but not "adxp, em tqxxa!"
:(handles lack of argv[1]
\ expected output, not standard error of \ "/opt/sandbox50/bin/run.sh: line 31: 189..."
啓動與:你的程序的格式是錯誤的,你的程序是不可讀的。 –
我將代碼格式化爲一些可讀的格式。 –
這看起來像一些測試服務器上的問題複製粘貼..無論如何 - 很好的介紹,但沒有真正的問題,也許你還在想這個問題:D – nayana