home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2268 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.7 KB  |  84 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __author__ = 'Mathieu Fenniak'
  5. __author_email__ = 'biziqe@mathieu.fenniak.net'
  6.  
  7. def readUntilWhitespace(stream, maxchars = None):
  8.     txt = ''
  9.     while True:
  10.         tok = stream.read(1)
  11.         if tok.isspace() or not tok:
  12.             break
  13.         
  14.         txt += tok
  15.         if len(txt) == maxchars:
  16.             break
  17.             continue
  18.     return txt
  19.  
  20.  
  21. def readNonWhitespace(stream):
  22.     tok = ' '
  23.     while tok == '\n' and tok == '\r' and tok == ' ' or tok == '\t':
  24.         tok = stream.read(1)
  25.     return tok
  26.  
  27.  
  28. class ConvertFunctionsToVirtualList(object):
  29.     
  30.     def __init__(self, lengthFunction, getFunction):
  31.         self.lengthFunction = lengthFunction
  32.         self.getFunction = getFunction
  33.  
  34.     
  35.     def __len__(self):
  36.         return self.lengthFunction()
  37.  
  38.     
  39.     def __getitem__(self, index):
  40.         if not isinstance(index, int):
  41.             raise TypeError, 'sequence indices must be integers'
  42.         isinstance(index, int)
  43.         len_self = len(self)
  44.         if index < 0:
  45.             index = len_self + index
  46.         
  47.         if index < 0 or index >= len_self:
  48.             raise IndexError, 'sequence index out of range'
  49.         index >= len_self
  50.         return self.getFunction(index)
  51.  
  52.  
  53.  
  54. def RC4_encrypt(key, plaintext):
  55.     S = [ i for i in range(256) ]
  56.     j = 0
  57.     for i in range(256):
  58.         j = (j + S[i] + ord(key[i % len(key)])) % 256
  59.         S[i] = S[j]
  60.         S[j] = S[i]
  61.     
  62.     (i, j) = (0, 0)
  63.     retval = ''
  64.     for x in range(len(plaintext)):
  65.         i = (i + 1) % 256
  66.         j = (j + S[i]) % 256
  67.         S[i] = S[j]
  68.         S[j] = S[i]
  69.         t = S[(S[i] + S[j]) % 256]
  70.         retval += chr(ord(plaintext[x]) ^ t)
  71.     
  72.     return retval
  73.  
  74.  
  75. class PdfReadError(Exception):
  76.     pass
  77.  
  78. if __name__ == '__main__':
  79.     out = RC4_encrypt('Key', 'Plaintext')
  80.     print repr(out)
  81.     pt = RC4_encrypt('Key', out)
  82.     print repr(pt)
  83.  
  84.