[Tutor] Problems padding a string with 0's while deconcatonating

Josh Yagy JYAGY1 at pride.hofstra.edu
Mon Dec 5 06:18:02 CET 2005


Hello everyone, this is my first time using the tutor e-mail, so if I mess up any common format or something just let me know :). Alright, for a little background, I'm in the process of writing a merkle-hellman cryptosystem for my CS15 class. I'm doing fine till I get to the decatonation of the long binary string into n-strings which will then be used to match up to the public key. I have the following code:

def binaryString(b, n):
	s=[]
	j=0
	while j < len(b):
		temp = b[j:j+n]
		s = s + [ temp ]
		j = j + n
	return s

which works for all intents and purposes, but I can't figure out a way to get it to pad the left of the string with zeros so that each of the subsets is n bits  long. As is, it will deconcatonate a given string into n-substrings, but not all of the substrings are n bits long. Any help would be greatly appreciated and sorry again if I didn't include anything I should. 
-Josh



More information about the Tutor mailing list