<s> from PIL import Image <EOL> import sys <EOL> import rs <EOL> rowstride = <NUM_LIT:255> <EOL> def encode ( input , output_filename ) : <EOL> """<STR_LIT>""" <EOL> coder = rs . RSCoder ( <NUM_LIT:255> , <NUM_LIT> ) <EOL> output = [ ] <EOL> while True : <EOL> block = input . read ( <NUM_LIT> ) <EOL> if not block : break <EOL> code = coder . encode ( block ) <EOL> output . append ( code ) <EOL> sys . stderr . write ( "<STR_LIT:.>" ) <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> out = Image . new ( "<STR_LIT:L>" , ( rowstride , len ( output ) ) ) <EOL> out . putdata ( "<STR_LIT>" . join ( output ) ) <EOL> out . save ( output_filename ) <EOL> def decode ( input_filename ) : <EOL> coder = rs . RSCoder ( <NUM_LIT:255> , <NUM_LIT> ) <EOL> input = Image . open ( input_filename ) <EOL> data = "<STR_LIT>" . join ( chr ( x ) for x in input . getdata ( ) ) <EOL> del input <EOL> blocknum = <NUM_LIT:0> <EOL> while True : <EOL> if blocknum * <NUM_LIT:255> > len ( data ) : <EOL> break <EOL> rowdata = data [ blocknum * <NUM_LIT:255> : ( blocknum + <NUM_LIT:1> ) * <NUM_LIT:255> ] <EOL> decoded = coder . decode ( rowdata ) <EOL> blocknum += <NUM_LIT:1> <EOL> sys . stdout . write ( str ( decoded ) ) <EOL> sys . stderr . write ( "<STR_LIT:.>" ) <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if "<STR_LIT>" == sys . argv [ <NUM_LIT:1> ] : <EOL> decode ( sys . argv [ <NUM_LIT:2> ] ) <EOL> else : <EOL> encode ( sys . stdin , sys . argv [ <NUM_LIT:1> ] ) </s>
