简单命令行的RC4算法的单个文件加密小程序,rc4文件加密小程序,简单文件加密import
简单命令行的RC4算法的单个文件加密小程序,rc4文件加密小程序,简单文件加密import
简单文件加密
import sysimport os#import datetimeimport time#This program is used to encrypt a file to another file and it take a RC4 algorithm to finish this job.#This is only a simple version, and will be improved later.#start_time = time.clock()if len(sys.argv) < 4: print 'usage:"python encrpyptiobn.py inputFilename outputFilename password"' exit(0)file_input = sys.argv[1]file_object = open(file_input)try: byte_data = file_object.read() byte_data = [ord(i) for i in byte_data]finally: file_object.close()file_output = sys.argv[2]file_object = open(file_output, 'wb')byte_write = byte_data[:]key = sys.argv[3]keyLength = len(key)key = [ord(i) for i in key]#s = [0 for i in range(256)]i = 0j = 0#k = [0 for i in range(256)]k = []tmp = 0#for i in range(256):# s[i] = i# k[i] = key[i % keyLength]s = [ i for i in range(256)]k = [ key[i % keyLength] for i in range(256)]for i in range(256): j = (j + s[i] + k[i]) % 256 tmp = s[i] s[i] = s[j] s[j] = tmpx = 0y = 0t = 0i = 0tmp = 0dataLength = len(byte_data)#for i in range(dataLength):while i < dataLength: x = (x + 1) % 256 y = (y + s[x]) % 256 tmp = s[x] s[x] = s[y] s[y] = tmp t = (s[x] + s[y])%256 byte_data[i] = byte_data[i] ^ s[t] i += 1out_bytes = ''i = 0#for i in range(dataLength):#while i < dataLength:# out_bytes += chr(byte_data[0])# del byte_data[0]# i += 1while i < dataLength: out_bytes+=chr(byte_data[i]) i += 1try: file_object.write(out_bytes)finally: file_object.close()#end_time = time.clock()#delavalue = (end_time-start_time)#delavalue = delavalue.seconds*1000+delavalue.microseconds#print "executing the program takes %s seconds" % delavalue
相关内容
- 删除当前目录下除当前脚本以外的文件和文件夹,当前
- 随意转换字符编码,字符编码,python转换字符编码
- 约瑟夫环问题,约瑟夫环,[Python]代码de
- string reverse,reverse,[Python]代码de
- 1.1 a string has all unique characters? use arrays and strings,char
- 把图片列表合成一个GIF动画图片,图片列表gif动画,im
- 批量删除文件,,test111.py#
- urllib2获取抓取的数据信息,urllib2获取抓取,urlfile = ur
- solaris系统巡检程序,solaris巡检程序,python+shell
- 基于用户的推荐算法余弦相似性实现,用户算法余弦相
评论关闭