All pastes #743171 Raw Edit

Miscellany

public python v1 · immutable
·published 2007-10-20 05:27 UTC
rendered paste body
#VET - Vigenere Encipherment Toolimport os, sysdef getText(string):	text = raw_input(string)	while len(text) == 0:		text = raw_input(string)	return textdef cipher(pchar, kchar):	pascii = ord(pchar)	kascii = ord(kchar)	if kchar.isalpha():		if kascii > 96:			kascii = kascii - 97		else:			kascii = kascii - 65	else:		print 'invalid key sequence'		raise SystemExit	if pchar.isalpha():		if pascii > 96:			pascii = pascii + kascii			if pascii > 122:				pascii = pascii - 26				return chr(pascii)			else:				return chr(pascii)		else:			pascii = pascii + kascii			if pascii > 90:				pascii = pascii - 26				return chr(pascii)			else: 				return chr(pascii)	else:		return pchardef cipherLoop(plaintext, key):	keycounter = 0	charcounter = 0	keytext = key.replace(' ','')	ciphertext = ''	while charcounter < len(plaintext):		keychar = keytext[keycounter]		plainchar = plaintext[charcounter]		charcounter = charcounter + 1		if plainchar != ' ':			ciphertext = ciphertext + cipher(plainchar, keychar)			keycounter = keycounter + 1			if keycounter == len(keytext):				keycounter = 0		else:			ciphertext = ciphertext + ' '	return ciphertextprint cipherLoop(getText('Please enter plaintext>'), getText('Please enter key>'))