Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
140 Kevin 1
def shift_string(str):
2
	'''Returns a list of strings that is the original string shifted by 1-25 places.
3
		The input string must have no whitespaces'''
4
	ret = []
5
	for i in range(0,26):
6
		output = ''
7
		for c in str:
8
			output += chr((ord(c)-65+i)%26 + 65) # Increment the letter by 1 mod(26) and append to output
9
		ret.append(output)
10
	return ret
11
 
12
if __name__ == '__main__':
13
	# input = raw_input("Enter string: ")
14
	input = 'NPVGP GIZGH LGZKP LKKLF EQZUN PGEHZ RKZOJ ZGZXZ MZQKA'
15
	input = input.upper()
16
	# Increment amount, here it's 26 for the english alphabet
17
	for i in range(0,26):
18
		output = ''
19
		for c in input:
20
			if c != ' ':
21
				# Increment the letter by 1 mod(26) and append to output
22
				output += chr((ord(c)-65+i)%26 + 65)
23
			else:
24
				# Ignore whitespaces
25
				output += ' '
26
		print output
27