コード例 #1
0
ファイル: problem_51_75.py プロジェクト: ifooth/ProjectEuler
def problem_59(keychars='abcdefghijklmnopqrstuvwxyz',keylen=3):
    ciphertext=list(next(data.openfile('cipher1.txt')).strip().split(','))     
    #ciphertext=encipher('leijiaominabc','zzz')
    #log.info(encipher('leijiaominabc','zzz'))
    #log.info(ciphertext)
    log.info(len(ciphertext))   
    texts = ['',0]
    a,b=divmod(len(ciphertext),keylen)
    for i in itertools.product(keychars,repeat=keylen):        
        cleartext = ''
        space = 0        
        for j in range(a):            
            for k in range(keylen):               
                t = int(ciphertext[keylen*j+k])^ord(i[k])
                if t == ord(' '):
                    space += 1 
                cleartext += chr(t)
        if b:
            for k in range(b):
                t = int(ciphertext[keylen*a+k])^ord(i[k])
                if t == ord(' '):
                    space += 1 
                cleartext += chr(t)
        if space > texts[1]:
            texts[1] = space
            texts[0] = cleartext
    log.info(texts)    
    return sum([ord(i) for i in texts[0]])    
コード例 #2
0
def problem_59(keychars='abcdefghijklmnopqrstuvwxyz', keylen=3):
    ciphertext = list(next(data.openfile('cipher1.txt')).strip().split(','))
    #ciphertext=encipher('leijiaominabc','zzz')
    #log.info(encipher('leijiaominabc','zzz'))
    #log.info(ciphertext)
    log.info(len(ciphertext))
    texts = ['', 0]
    a, b = divmod(len(ciphertext), keylen)
    for i in itertools.product(keychars, repeat=keylen):
        cleartext = ''
        space = 0
        for j in range(a):
            for k in range(keylen):
                t = int(ciphertext[keylen * j + k]) ^ ord(i[k])
                if t == ord(' '):
                    space += 1
                cleartext += chr(t)
        if b:
            for k in range(b):
                t = int(ciphertext[keylen * a + k]) ^ ord(i[k])
                if t == ord(' '):
                    space += 1
                cleartext += chr(t)
        if space > texts[1]:
            texts[1] = space
            texts[0] = cleartext
    log.info(texts)
    return sum([ord(i) for i in texts[0]])
コード例 #3
0
ファイル: problem_51_75.py プロジェクト: ifooth/ProjectEuler
def problem_54(): #Diamond Club Heart Spade
    d=data.openfile('poker.txt').read().split('\n')
    #log.info(d)
    log.info(len(d))

    s=0         
    for i in d:
        poker(i).win()
    return s
コード例 #4
0
def problem_54():  #Diamond Club Heart Spade
    d = data.openfile('poker.txt').read().split('\n')
    #log.info(d)
    log.info(len(d))

    s = 0
    for i in d:
        poker(i).win()
    return s