python学习笔记[1]-凯撒密码
#!/usr/bin/python #FileName:caesar.py #Code:UTF-8 import sys def caesarEnCode(string,tag): ChgString = "" for s in string: if s.islower(): ChgString += chr((ord(s)-ord('a')+tag)%26+ord('a')) elif s.isupper(): ChgString += chr((ord(s)-ord('A')+tag)%26+ord('A')) return ChgString def caesarDeCode(string,tag): ChgString = "" for s in string: if s.islower(): ChgString += chr((ord(s)-ord('a')+tag)%26+ord('a')) elif s.isupper(): ChgString += chr((ord(s)-ord('A')+tag)%26+ord('A')) return ChgString return string if __name__=='__main__': flag=sys.argv[1] string=sys.argv[2] tag = 3 if flag == 'E': restring = caesarEnCode(string,tag) elif flag == 'D': restring = caesarDeCode(string,tag) print restring