#-*- coding:utf-8 -*-
#from crypto101
from itertools import cycle
#相当于根据key打乱一个排列
def key_schedule(key):
	s = range(256)
	#返回一个无线循环的生成器
	key_bytes = cycle(ord(x) for x in key)
	j = 0
	for i in xrange(256):
		# print next(key_bytes)
		j = (j + s[i] + next(key_bytes)) % 256
		s[i], s[j] = s[j], s[i]
		return s
key_schedule("123")

#相当于随机生成一个字节
def pseudorandom_generator(s):
	j = 0
	for i in cycle(range(256)):
		j = (j + s[i]) % 256
		s[i], s[j] = s[j], s[i]
		k = (s[i] + s[j]) % 256
		yield s[k]