Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
#!/usr/bin/python2 import sys import math def has_decimal(a): if(math.floor(a) !=..
Decoded Output download
<? #!/usr/bin/python2
import sys
import math
def has_decimal(a):
if(math.floor(a) != a):
return True
else:
return False
def is_prime(a):
for c in range(2, int(math.floor(a / 2)) + 1):
if (not has_decimal(float(a) / float(c))):
return False
c += 1
return True
def phi(a, b):
return (a - 1) * (b - 1)
def pow_mod(a, b, c):
m = 1
for i in range(0, b):
m = (m * a) % c
return m
def encrypt(string, public_key):
ret = [0] * len(string)
public_key = public_key.split(":")
for c in range(0, len(string)):
ret[c] = str(pow_mod(ord(string[c]), int(public_key[1]), int(public_key[0])))
c += 1
return ":".join(ret)
def get_input():
ret = ""
for line in sys.stdin:
ret += line
return ret
def main():
if (len(sys.argv) != 4):
print "Usage: " + sys.argv[0] + " [P] [Q] [E] < ./input.dat"
print " ...where P, Q, and E are prime numbers"
print " ...and 1 < E < phi(P*Q)"
print " ...and E is coprime to (P*Q)"
exit(1)
elif (not is_prime(int(sys.argv[1])) or not is_prime(int(sys.argv[2]))):
print "P and Q must be prime"
exit(1)
elif (not has_decimal(float((int(sys.argv[1]) * int(sys.argv[2]))) / float(sys.argv[3]))):
print "E must not be a factor of (P*Q)"
exit(1)
elif (int(sys.argv[3]) < 1 or int(sys.argv[3]) > phi(int(sys.argv[1]), int(sys.argv[2]))):
print "E must be greater than 1 and less that phi(P*Q)"
exit(1)
else:
p = int(sys.argv[1])
q = int(sys.argv[2])
e = int(sys.argv[3])
public_key = str(p * q) + ":" + str(e)
plain = get_input()
print "Public Key: " + public_key
encrypted = encrypt(plain, public_key)
print "Encrypted: " + encrypted
main()
Public Key: 4856437:139
Encrypted: 1634135:130456:4558738:385491:528551:4493069:1506952:4558738:528551:2636859:3271344:130456:4558738:1506952:53561:528551 ?>
Did this file decode correctly?
Original Code
#!/usr/bin/python2
import sys
import math
def has_decimal(a):
if(math.floor(a) != a):
return True
else:
return False
def is_prime(a):
for c in range(2, int(math.floor(a / 2)) + 1):
if (not has_decimal(float(a) / float(c))):
return False
c += 1
return True
def phi(a, b):
return (a - 1) * (b - 1)
def pow_mod(a, b, c):
m = 1
for i in range(0, b):
m = (m * a) % c
return m
def encrypt(string, public_key):
ret = [0] * len(string)
public_key = public_key.split(":")
for c in range(0, len(string)):
ret[c] = str(pow_mod(ord(string[c]), int(public_key[1]), int(public_key[0])))
c += 1
return ":".join(ret)
def get_input():
ret = ""
for line in sys.stdin:
ret += line
return ret
def main():
if (len(sys.argv) != 4):
print "Usage: " + sys.argv[0] + " [P] [Q] [E] < ./input.dat"
print "\t...where P, Q, and E are prime numbers"
print "\t...and 1 < E < phi(P*Q)"
print "\t...and E is coprime to (P*Q)"
exit(1)
elif (not is_prime(int(sys.argv[1])) or not is_prime(int(sys.argv[2]))):
print "P and Q must be prime"
exit(1)
elif (not has_decimal(float((int(sys.argv[1]) * int(sys.argv[2]))) / float(sys.argv[3]))):
print "E must not be a factor of (P*Q)"
exit(1)
elif (int(sys.argv[3]) < 1 or int(sys.argv[3]) > phi(int(sys.argv[1]), int(sys.argv[2]))):
print "E must be greater than 1 and less that phi(P*Q)"
exit(1)
else:
p = int(sys.argv[1])
q = int(sys.argv[2])
e = int(sys.argv[3])
public_key = str(p * q) + ":" + str(e)
plain = get_input()
print "Public Key: " + public_key
encrypted = encrypt(plain, public_key)
print "Encrypted: " + encrypted
main()
Public Key: 4856437:139
Encrypted: 1634135:130456:4558738:385491:528551:4493069:1506952:4558738:528551:2636859:3271344:130456:4558738:1506952:53561:528551
Function Calls
| None |
Stats
| MD5 | ef50ad9fe8a87292533071e0130755b2 |
| Eval Count | 0 |
| Decode Time | 92 ms |