如下代码是以偏移量为13展开计算的。123
源代码如下:
sr1="abcdefghijklmnopqrstuvwxyz"sr2=sr1.upper()
sr=sr1+sr1+sr2+sr2
st="The Zen of Python"sResult=""for j in st:if j==" ":
sResult = sResult +" "
continue
i=sr.find(j)if(i>-1):
sResult=sResult+sr[i+13]print sResult12345678910111213
运行结果为:
Gur Mra bs Clguba
#include <stdio.h>#define isletter( c ) ( ((c)>='a'&&(c)<='z') || ((c)>='A'&&(c)<='Z') )
void Enc( const char *str, char *out, int key )
{
int i = 0
while( str[i] )
陪者配{
if ( isletter( str[i] ) )
{
out[i] = str[i] + key
if ( ! isletter( out[i]) )
out[i] -= 26
}
else
out[i] = str[i]
i++
}
out[i] = 0
}
void Denc( const char *str, char *out, int key )
{
int i=0
while( str[i] )
{
嫌知 if ( isletter( str[i] ) )
芦指 {
out[i] = str[i] - key
if ( ! isletter( out[i] ) )
out[i] += 26
}
else
out[i] = str[i]
i++
}
out[i] = 0
}
int main()
{
char out[100], out2[100]
Enc( "THE QUICK BROWn fox jumps over THE LAZY DOG", out, 3 )
printf( "%s\n", out )
Denc( out, out2, 3 )
printf( "%s\n", out2 )
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)