python lists error
Posted
by mekasperasky
on Stack Overflow
See other posts from Stack Overflow
or by mekasperasky
Published on 2010-04-10T06:30:41Z
Indexed on
2010/04/10
6:33 UTC
Read the original article
Hit count: 406
python
#defining the magic constants
p=0xb7e15163
q=0x9e3779b9
pt=list()
pt1=list()
ct=list()
pt2=list()
#pt[0]=0pt1[0]=ct[0]=pt1[1]=ct[1]=0
s=[]
l=[]
b=8
key=[0,0,0,0,0,0,0,0,0]
w=8
t=16
def enc(c,d):
for i in range(1,r):
A=A+s[0]
B=B+s[1]
A=A^B
A=str(A)
B=str(B)
A=A[len(B):]+A[:len(B)]
B=B^A
A=str(A)
B=str(B)
B=B[len(A):]+B[:len(B)]
A=A+s[2*i]
B=B+s[2*i+1]
ct.append(A)
ct.append(B)
def denc():
for i in range(r,1):
A=ct[0]
B=ct[1]
B=B-s[2*i+1]
B=B[len(c):] + B[:len(c)]
B=B^A
A=A-s[2*i]
A=A[:len(B)]+c[len(B):]
A=A^B
pt1[1]=B-S[1]
pt1[0]=A-S[0]
def setup(k):
u=w/8
for i in range(b-1,0):
l.append(l[i/u:8]+l[8:i/u]+k[i])
s.append(p)
for i in range(1,t-1):
s.append(s[i-1] + q)
i=j=0
A=B=0
for i in range(0,3*t):
A=s.append(s[i]+A+B)
B=s.append(s[:3]+s[3:])
#B=l.append((l[j]+A+B))
ll=len(str(A))+len(str(B))
B=l.append(l[:ll]+l[ll:])
i=(i+1)%t
j=(j+1)%t
def pri(g):
for k in range(0,w):
print g & 0xFF
#for i in range(0,b):
#key[i]=ct[0]%(255-j)
pt1=[raw_input()]
pt1=[raw_input()]
setup(key)
enc(pt1,ct)
denc(ct,pt2)
print("key")
print(key)
print("plaintext")
printword(pt1[0]),printword(pt1[1])
printword(ct[0]),printword(ct[1])
the list l is always going out of index though it should not . I am not able to take the length of the string A even though it is a string .Once i convert it to string i am not able to add it in s[j]+A+B. How to get around such errors and make the code more hygenic .. This is an rc5 cipher.
© Stack Overflow or respective owner