Created
December 21, 2011 21:08
-
-
Save timmc/1507712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Read from stdin and print chunks with checksums.""" | |
from __future__ import print_function | |
import sys | |
import md5 | |
chunk_size = 40 | |
def part_str(s, l): | |
"""Partition string s into chunks of size l, potentially ragged at end.""" | |
ret = [] | |
while len(s) > 0: | |
ret.append(s[:l]) | |
s = s[l:] | |
return ret | |
def main(): | |
print("Delimiters [ and ], newline ...") | |
for line in sys.stdin.readlines(): | |
line = line.rstrip("\r\n") | |
for chunk in part_str(line, chunk_size): | |
checksum = md5.md5(chunk).hexdigest() | |
fixchunk = ("[" + chunk + "]").ljust(45, " ") | |
print("%s %s" % (fixchunk, checksum)) | |
print("...") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment