exec('moveLength = int(raw_input("Input raw_input amount, expect a int number"))\nprint "".join([dict(zip(list("abcdefghijklmnopqrstuvwxyz"), [list("abcdefghijklmnopqrstuvwxyz")[(i + moveLength) % 26] for i in range(26)]))[x] for x in list(raw_input("String to change:"))])')
楼主分没给够, 所以只能看到这样的代码喽……o((≧▽≦o) ......
它的原理是字母与字母之间的替换。例如26个字母都向后移动K位。若K等于2,则A用C代替,B用D代替,以此类推
k是移动的位数,例如移动两位,当前字母是c,那么c-a=2,再加2,4%26=4(保证变换后的在26个字母的范围内),然后a+4即为e
凯撒密码就是简单的加上一个数,'a'+3='d';'z'+3='c' 假设原文全是小写字母,那么 char plain[N]={...}; //明文 char cipher[N]={};//密文 int key=3; int i=0,temp; for(i=0;iN;i++) {if(plain[i]!=' ') {temp=plain[i]+key-'a'; temp=temp%26; cipher[i]=temp+'a'; } else cipher[i]=plain[i]; } 这样就完成了加密,密文数组里面就是对原文加密后的密文,key是密钥。
解:
Private Sub cmdCode_Click()
Dim pt As String ' 明文
Dim ct As String ' 密文
Dim n As Integer ' 字母在字母表中的序号
Dim ch As String
Dim i As Integer
pt = txtPt.Text
ct = ""
For i = 1 To Len(pt)
ch = Mid(pt, i, 1)
Select Case ch
Case "A" To "Z"
n = Asc(ch) - Asc("A")
n = (n + 3) Mod 26
ch = Chr(n + 65)
Case "a" To "z"
n = asc(ch)-asc("A")
n = (n + 3) Mod 26
ch = Chr(n + 97)
End Select
ct = trim(ct ch)
Next i
txtCt.Text = ct
End Sub
#include stdio.h
char s[]="Beijing Technology and Business University (BTBU) is a key state-run university with comprehensive disciplines covering Arts, Sciences, Engineering, Law, Economics, History, Philosophy and Management.";
void fun(char *s,int n)
{
int i=0;
while(s[i]!=0)
{
if(s[i]='z's[i]='a')
{
s[i] += n;
if(s[i]'z') s[i] -=24;
}
else if(s[i]='Z's[i]='A')
{
s[i] += n;
if(s[i]'Z') s[i] -=24;
}
i++;
}
}
void main()
{
fun(s,3);
puts(s);
}