aLIST="abcdefghijklmnopqrstuvwxyz"
def c_enc(Msg, K):
c=""
for i in Msg:
idx=aLIST.find(i) #알파벳->숫자
idx=(idx+K)%26 #암호화
c=c+aLIST[idx] #숫자->알파벳
return c
def c_dec(C,K):
p=""
for i in C:
idx=aLIST.find(i) #알파벳->숫자
idx=(idx-K)%26
p=p+aLIST[idx]
return p
def v_dec(msg, k):
p=""
klen=len(k)
kidx=[]
for i in k:
idx = aLIST.find(i)
kidx.append(idx)
cnt=0
for i in msg:
idx = aLIST.find(i)
idx = (idx-kidx[cnt])%26
p = p+(aLIST[idx])
cnt = (cnt+1)%klen
return p
ct = "aebcfwedmkpfwxpngkqlhjemwqkoxajxeqbcfshgwkouyw"
for i in range(0,26):
for j in range(0,26):
for k in range(0, 26):
for l in range(0, 26):
tmp =""
tmp = tmp+aLIST[i]
tmp = tmp+aLIST[j]
tmp = tmp +aLIST[k]
tmp = tmp+aLIST[l]
pt = v_dec(ct, tmp)
if pt[0]=="i" and pt[1]=="m" and pt[2]=="f":
print("keY:", tmp, "msg:", pt)