Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For prog assignment 2, CTR method 2 #1

Open
108anup opened this issue Jan 10, 2018 · 0 comments
Open

For prog assignment 2, CTR method 2 #1

108anup opened this issue Jan 10, 2018 · 0 comments

Comments

@108anup
Copy link

108anup commented Jan 10, 2018

def decrypt(msg, key):
        key = base64.b16decode(key, True)
        msg = base64.b16decode(msg, True)
        init_val = msg[:s]
        msg = msg[s:]
        ctr = int(base64.b16encode(init_val),16)
        cipher = AES.new(key, AES.MODE_ECB)
        pt = ""
        for i in range(0,len(msg)/s):           
            c = cipher.encrypt(ctr2str(ctr))
            ctr = (ctr + 1) % 2**128
            pt += xor(msg[i*s:(i+1)*s], c)
            
        c = cipher.encrypt(ctr2str(ctr))
        pt += xor(msg[len(msg) - len(msg)%s:], c)
        return pt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant