Changeset 247

Show
Ignore:
Timestamp:
03/25/09 01:31:32 (3 years ago)
Author:
ocjhb
Message:

container now with subitems

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/oc2/rsa.py

    r246 r247  
    2020import random    # For picking semi-random numbers 
    2121import types 
    22 from pickle import dumps, loads 
    23 import base64 
    24 import zlib 
    2522 
    2623RANDOM_DEV="/dev/urandom" 
     
    370367    return (m * secret) % n 
    371368 
    372      
    373  
    374 def picklechops(chops): 
    375     """Pickles and base64encodes it's argument chops""" 
    376  
    377     value   = zlib.compress(dumps(chops)) 
    378     encoded = base64.encodestring(value) 
    379     return encoded.strip() 
    380  
    381 def unpicklechops(string): 
    382     """base64decodes and unpickes it's argument string into chops""" 
    383  
    384     return loads(zlib.decompress(base64.decodestring(string))) 
    385  
    386369def chopstring(message, key, n, funcref): 
    387370    """Splits 'message' into chops that are at most as long as n, 
     
    410393        cypher.append(funcref(value, key, n)) 
    411394 
    412     #return picklechops(cypher) 
    413395    return cypher[0] 
    414396 
     
    421403    message = "" 
    422404    chops = [chops] 
    423     #chops = unpicklechops(chops) 
    424405     
    425406    for cpart in chops: 
     
    556537    if 1: 
    557538        import time 
    558         #(pub,priv) =  gen_pubpriv_keys(512) 
    559         pub = {'e': 59343568823711559206614914329434374961303042335788099534897501357955675804133L,  
    560                'n': 32793647770017443581051908007908006621376604150499221366839445678176407494654130256572721798731647281073382247358431120858829497973290288823842062554766872356043862368004460824686561544242774370448685624290963022007959843337482265073763255429596031300239158232169931316001844162136279539357507455710562227577L} 
    561         priv = {'q': 3660876769483489857077409618418989781902917148342703560038011826242773069902176126219730148875372119227365538620396693688963051979724315365417720940740849L,  
    562                 'p': 8957867154497055858370988090953024497950216741166048812169220114248696092230327733254526217831517389137130597830562133311139440841609128753512364848094473L,  
    563                 'd': 12619589565384678078150569778102981741046267149118420445896125941979396328586657133712760591528167393457329828435758755256948329844592838106750783634900284025380032774546264335257012829516042607077111098646252442031819834114954318384114125879377117610343879752299012777002244350133926279173002674800640331117L} 
     539        #(pub,priv) =  gen_pubpriv_keys(1024) 
     540        if 1: 
     541            pub = {'e': 59343568823711559206614914329434374961303042335788099534897501357955675804133L,  
     542                   'n': 32793647770017443581051908007908006621376604150499221366839445678176407494654130256572721798731647281073382247358431120858829497973290288823842062554766872356043862368004460824686561544242774370448685624290963022007959843337482265073763255429596031300239158232169931316001844162136279539357507455710562227577L} 
     543            priv = {'q': 3660876769483489857077409618418989781902917148342703560038011826242773069902176126219730148875372119227365538620396693688963051979724315365417720940740849L,  
     544                    'p': 8957867154497055858370988090953024497950216741166048812169220114248696092230327733254526217831517389137130597830562133311139440841609128753512364848094473L,  
     545                    'd': 12619589565384678078150569778102981741046267149118420445896125941979396328586657133712760591528167393457329828435758755256948329844592838106750783634900284025380032774546264335257012829516042607077111098646252442031819834114954318384114125879377117610343879752299012777002244350133926279173002674800640331117L} 
     546        if 0:                     
     547            (pub,priv) = ({'e': 3197601411731116245564574341873883965700807663084732800379376818822337768214254275271880556652543127861042149268538435129289119875433847550131501030387489L, 'n': 10010369815382334240798530070718437854966721919010883362239947723044651469296597049454697875962523892167961291050690952736009970933207150773523631818070845272169487515533531012017986671583117870935704791444203091193928433685036216475710517809854134259468721246954372989146266743601614235731605829521314456547427727170490340220674730134652649494795255568521600458207445549064461533102227417295842548674337715761362209701734789853469920681184060067484771558465649908138716260602630770402224385695023184536234858539880642604697788322269392260439339765412460944589951571879796455505538134420317166479947358156062601693631L}, {'q': 71965600310892660429596898829670710653460148180418095123381449844052583795523012040229068564004895983101524115981347946055591335247903874583493068435665706247560257067715751690858970054084093796406191757154228889454862489531588573733962647071944624542539072044760521321849853532919544810806179365743581833777L, 'p': 139099372090795607726534110588106724714748422622835743921578772078079056922772905042826722454890797681407412421239584468016215098928247799729322355221381502409668675456356288320338371140589835466925402699800592201081119770108520423450701555386146286042071274331899104700802281153510654832285005494641183409903L, 'd': 2303141903135405741196770316647349478451046851656460345238126953851335354457956582261071364112927329063172609648667594153989314522741915259780604774082900187421379799944807777478001765690017634728386784574675440128718738783220812396390380020488828055736972630556491383856716073773079586029351343732817861978611326631064317705218919924700761528865528832464733884127079042865050020476303293874373222849912706661252250304706695160160822827622086731394008802874568358702895903468129589361385276702313798198182238681153517515581052056557552995405472004415453043300567819425403784410663519000867938462388941313183838315329L})                     
    564548        if 0: 
    565549            #full 
     
    607591        #blinding 
    608592        t = time.time() 
    609         message = 'serial '*10 
     593        message = 's'*64 
     594        print len(message) 
    610595        #print 'cleartext ', message 
    611596        unblinder = getUnblinder(pub['n'])