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

Cesar Cipher implemented in python#49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
JordaoA wants to merge1 commit intoabranhe:master
base:master
Choose a base branch
Loading
fromJordaoA:patch-2
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletionsallalgorithms/string/cesarCipher.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
# String Algorithms
# Contributed by: JordaoA
#Cesar Cipher implemented in python

class cipher():
#Constructor method
def __init__(self,posCipher,jump):
self.letters = ["A","B","C","D","E",
"F","G","H","I","J","K","L",
"M","N","O","P","Q","R","S",
"T","U","V","W","X","Y","Z"] #Alphabet in UPPERCASE
self.posCipher = posCipher #encrypted word
self.jump = jump #jump between the letters

#Method responsible for ignore the case of all letters of the word
def ignoreCase(self):
newPosCipher = ""

for i in range(len(self.posCipher)):
newPosCipher += self.posCipher[i].upper()

self.posCipher = newPosCipher #transforming the old word

#Method responsible for search index of each letter of the word in the alphabet
def returnIndex(self,element, listOfLetters):
index = 0 #letter index

for i in range(len(listOfLetters)):
if element == listOfLetters[i]:
index = i
break

return index

#Method responsible for deciphering the word given by the user according to the letter jump
def cipherC(self):

self.ignoreCase()
preCipher = "" #decipher word

for j in range(len(self.posCipher)):
index = self.returnIndex(self.posCipher[j], self.letters)

if (index - self.jump) > 25:
preCipher += self.letters[(index - self.jump) % 26]

else:
preCipher += self.letters[(index - self.jump)]

return preCipher

[8]ページ先頭

©2009-2025 Movatter.jp