Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
/pythonPublic archive

Commitdcbc0ea

Browse files
authored
Railfence Cipher implementation in cipher
1 parente743b42 commitdcbc0ea

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
defrailencrypt(st,k):
2+
c=0
3+
x=0
4+
m=[[0]* (len(st))foriinrange(k)]
5+
forrinrange(len(st)):
6+
m[c][r]=st[r]
7+
ifx==0:
8+
ifc== (k-1):
9+
x=1
10+
c-=1
11+
else:
12+
c+=1
13+
else:
14+
ifc==0:
15+
x=0
16+
c+=1
17+
else:
18+
c-=1
19+
20+
result= []
21+
foriinrange(k):
22+
forjinrange(len(st)):
23+
ifm[i][j]!=0:
24+
result.append(m[i][j])
25+
print("CipherText:","" .join(result))
26+
27+
defraildecrypt(st,k):
28+
c ,x=0 ,0
29+
m=[[0]* (len(st))foriinrange(k)]
30+
forrinrange(len(st)):
31+
m[c][r]=1
32+
ifx==0:
33+
ifc== (k-1):
34+
x=1
35+
c-=1
36+
else:
37+
c+=1
38+
else:
39+
ifc==0:
40+
x=0
41+
c+=1
42+
else:
43+
c-=1
44+
result= []
45+
c ,x=0 ,0
46+
foriinrange(k):
47+
forjinrange(len(st)):
48+
ifm[i][j]==1:
49+
m[i][j]=st[x]
50+
x+=1
51+
forrinrange(len(st)):
52+
ifm[c][r]!=0:
53+
result.append(m[c][r])
54+
ifx==0:
55+
ifc== (k-1):
56+
x=1
57+
c-=1
58+
else:
59+
c+=1
60+
else:
61+
ifc==0:
62+
x=0
63+
c+=1
64+
else:
65+
c-=1
66+
print("PlainText:","" .join(result))
67+
68+
if__name__=="__main__":
69+
string=input("Enter the Message:")
70+
string=string.upper()
71+
key=int(input("Enter the Key:"))
72+
n=int(input("1.Encryption\n2.Decryption\nInput Your choice:"))
73+
if(n==1):
74+
railencrypt(string,key)
75+
elif(n==2):
76+
raildecrypt(string,key)
77+
else:
78+
print("Error")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp