addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Alamo City Python Group Message Board › Python CTF Challenge

Python CTF Challenge

user 89514942
San Antonio, TX
Post #: 1
Here is a Python challenge below. Can anybody offer any help to solve this?

import random
# bleh, figuring out how to decrypt stuff is hard...
# good thing there's a service running at wherever the problem description says

ciphertext = (191399506312570941099748175129508449452­3614652689932582615239311126533985633211­7664760030665587057736341341088217L, 6981451340216985983024432325647526079415­7685719960610664145090689046057195658068­7935633542046758257396595842622837937744­7329201133443741822196232606915765082265­97259307160898152603847317630021751538L,­ 375)
pubkey = 9140361246050720958964986450403171104446­7769368162510130303651530726925696469551­7984683462742136579499746530214988587637­6944965165803509199953554077448911258149­50650516684386468562425056693756001673L

def numbits(k):
if k == 1:
return 1
return int(math.ceil(math.log(k,2))) + (1 if k % 2 == 0 else 0)

def strtoint(s):
if len(s) == 0:
return 0
if len(s) == 1:
return ord(s[0])
return (ord(s[0]) << (8 * len(s[1:]))) | strtoint(s[1:])

def inttostr(s):
if s == 0:
return ""
c = chr(s & 0xFF)
return inttostr(s >> 8) + c

def encrypt(m, N):
L = numbits(m)
r = random.randint(2, N-1)
x = pow(r, 2, N)
y = x
l = 0
for k in range(0, L):
l = l << 1
l |= y & 1
y = pow(y, 2, N)
return (m ^ l, y, L)
Doug M.
user 27750462
Group Organizer
San Antonio, TX
Post #: 8
It sucks that this forum trims white space. It's impossible to read this code. :(
user 89514942
San Antonio, TX
Post #: 2
Yeah I noticed that. This challenge was a little bit harder than I originally thought, I was hoping the hardest part was just interpreting the code, but there was a little more than that. If anybody is interested, there is a write up of the solution at https://blog.inexplic...­

I did learn some python just attempting to understand it though. I am now on Lesson 4 of Code Academy Python.

Powered by mvnForum

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy