SlideShare a Scribd company logo
1 of 19
Download to read offline
RSA WITH WEAK
KEYS
Dedicated to Rivest, Shamir and Adleman
CORE ISSUE
With today's high-speed computation
intensive machines, the cryptographic
protocol based on the difficulty of
large primes factorization such as RSA
(and other related algorithms as such),
would render RSA-based public-key
cryptography insecure.
Khan Farhan Rafat
Programming for Security Professionals
1
Contents
1. Types of Attack on any Network/Communication.................................................................. 3
1.1 Passive Attacks ..................................................................................................................... 3
1.2 Active Attacks....................................................................................................................... 3
2. Cryptography........................................................................................................................... 3
2.1 Encryption............................................................................................................................. 3
2.2 Decryption............................................................................................................................. 3
3. Why Cryptography .................................................................................................................. 3
4. Cryptographic Techniques / Types of Ciphers........................................................................ 4
4.1 Transposition......................................................................................................................... 4
4.1.1 Encipher......................................................................................................................... 4
4.1.2 Decipher......................................................................................................................... 5
4.2 Substitution ........................................................................................................................... 5
4.2.1 Morse Code.................................................................................................................... 5
5. Types of Cryptography ........................................................................................................... 5
5.1 Symmetric Cryptography................................................................................................. 6
Examples................................................................................................................................. 6
5.1.1 Advantages......................................................................................................................... 6
5.1.2 Limitation........................................................................................................................... 6
5.2 Asymmetric Cryptography.................................................................................................... 7
Examples................................................................................................................................. 7
5.2.1 Advantages......................................................................................................................... 7
5.2.2 Limitation........................................................................................................................... 7
6. Applications:........................................................................................................................... 7
7. Some Mathematical Concepts................................................................................................. 8
7.1 Prime Numbers ..................................................................................................................... 8
7.2 Multiplicative Inverse........................................................................................................... 8
7.3 The Greatest Common Divisor............................................................................................. 8
7.4 Euler's Totient....................................................................................................................... 9
8. How RSA Works .................................................................................................................... 9
8.1 Working Example................................................................................................................. 9
9. The Problem.......................................................................................................................... 10
2
10. The Problem Statement...................................................................................................... 11
11. Proposed Solution.............................................................................................................. 11
12. Implementation Details...................................................................................................... 11
13. The Source Code................................................................................................................ 11
13.1 Encryption......................................................................................................................... 12
13.2 Decryption......................................................................................................................... 12
14. Program Generated Output ................................................................................................ 16
15. Screenshot.......................................................................................................................... 17
16. Advantages......................................................................................................................... 17
17. Future Work....................................................................................................................... 17
Reference ...................................................................................................................................... 18
3
1. Types of Attack on any Network/Communication
The two main types of attacks that an adversary may launch on a network include:
1.1 Passive Attacks
Passive attacks can be online where an attacker only tries to read/listen to a network segment for
any subtle information as it travels across the network or offline in which an attacker extracts and
stores real-time traffic for lateral views.
1.2 Active Attacks
In this type of attack, a malicious attacker attempts in real time to satirize as a client or server to
intercept the ongoing communication for modifying (to add and or delete/drop) the contents before
letting these go to their intended destination.
2. Cryptography
The word Cryptography or cryptology derived from the Greek words i) κρυπτός kryptós, which
means "hidden, secret"; and ii) γράφειν “graphein,” meaning "writing," or -λογία -logia, "study,"
respectively). It is the modus operandi for secure communication in the perspective of
eavesdroppers called adversaries. In general, cryptography deals with creating and evaluating
protocols that prevent the unauthorized or the public from intruding into private or secret
communication.
Disciplines such as mathematics, computer science, communication science, electrical
engineering, and physics are at the heart of Modern Cryptography.
2.1 Encryption
It is the process of making a clear message (Plain Text) unintelligible (Ciphered text or
Cryptogram) whose mathematical representation is as follows:
𝐸 𝑘(𝑀) = 𝐶 … … (1)
Where E denotes the encryption algorithm that takes some input message M, operates upon it
using some Key K to produce the ciphered message.
2.2 Decryption
It takes a ciphered text and converts it into a readable form. The mathematical depiction of the
process is as follows:
Equation (1) => 𝐷 𝑘(𝐶) = 𝐷 𝑘(𝐸 𝑘(𝑀)) = M … … (2)
Where D denotes the decryption algorithm that takes some input ciphered text C, operates upon
it using some Key K to produce the message.
3. Why Cryptography
Cryptography is the means by which communications gets protected over untrusted networks.
Modern cryptography also focuses on other aspects of information security that includes:
4
i) data confidentiality
ii) data integrity
iii) authentication and
iv) Non-Repudiation.
Multiple endpoints regarding multiple clients and one or more back-end servers is often a salient
trait of Software systems. However, the network such as the Internet, over which these client/
servers communicate cannot be trustworthy.
The cryptographic protocols like SSL/TLS provide confidentiality and integrity protection to the
contents that get exchanged online from tampering and eavesdropping.
Authenticity ensures that actual users are communicating with the systems (HMAC, RSA
encryption, and other such schemes).
Protecting Data at rest: Cryptography is also employed to protect data at rest by encrypting the
data resident on a removable disk or in a database to prevent unauthorized disclosure of sensitive
data should the physical media gets lost or stolen. Likewise, it also provides integrity protection to
detect malicious meddling of the data at rest.
4. Cryptographic Techniques / Types of Ciphers
Since its inception, Cryptography makes use of the two techniques namely:
4.1 Transposition
This technique intends to achieve secrecy by strewing the alphabets/words constituting a message.
Following is one such way (employed in this report) of doing the transposition:
4.1.1 Encipher
Let our Message be: a quick brown fox jumps over the lazy dog
Arranging the message in a Matrix (? X 8 columns) form, using column Labels from the Secret
Key (8) [6, 2, 4, 1, 7, 3, 8, 5]
Taking out alphabets in increasing order using column labels from above Matrix gives the Cipher
Text as:
u cq aikwr oobnfu pj xmsrvteeo dzl ao dqdepmgcw
6 2 4 1 7 3 8 5
a q u i c k
b r o w n f o
x j u m p s
o v e r t h e
l a z y d o
g d p q c e w m
5
4.1.2 Decipher
Let the Ciphertext be: u cq aikwr oobnfu pj xmsrvteeo dzl ao dqdepmgcw
Arranging the ciphered text in a Matrix (? X 8 columns) form, using column Labels from the Secret
Key (8) [6, 2, 4, 1, 7, 3, 8, 5]
Extracting the text row-wise gives the secret message: a quick brown fox jumps over the lazy
dog after discarding the gibberish text.
4.2 Substitution
This technique intends to achieve secrecy by replacing/substituting the alphabets/words
constituting a message. Following serves as an example:
4.2.1 Morse Code developed for use by telegraph operators and first used for communication by
Titanic is a well-known example of a substitution cipher. Here, the alphabets/letters in a message
get replaced/substituted by dots and dashes. This code has an international adaptation. The Morse
code for the international distress signal (SOS) is ... --- .... Table 1 shows the alphabets along with
their respective Morse Codes.
Table 1: Morse Code Representation (http://www-math.ucdenver.edu/~wcherowi/courses/m5410/m5410cc.html)
5. Types of Cryptography
Computational hardness or trivial assumptions are critical to cryptographic algorithm design and
development, which means that such algorithms are breakable in theory but infeasible to
materialize by any well-known means. Examples include integer factorization algorithms (RSA
6 2 4 1 7 3 8 5
a q u i c k
b r o w n f o
x j u m p s
o v e r t h e
l a z y d o
g d p q c e w m
6
algorithm) and discrete logarithms (Elgamal Key exchange protocol). However, there exist
information-theoretically secure systems which stand unbroken even with unlimited computing
power. The one-time pad (OTP) often quoted as an example of such type of system.
Cryptography, in general, is classified into two categories:
5.1Symmetric Cryptography
In symmetric cryptography, the sender and the receiver uses one shared (by some means) / pre-
agreed key for both encryption and decryption.
Figure 1 graphically illustrates the symmetric cryptography process.
Figure 1. Symmetric Cryptography
Remember that both sender and the receiver share and use the same key for encryption and
decryption respectively.
Examples
Block Cypher [Advanced Encryption Standard (AES)], Stream Cyphers (CryptMT)
5.1.1 Advantages
Symmetric key cryptography is:
 Extremely fast
 Can encrypt bulk of data (such as disk partition or the database)
5.1.2 Limitation
 Sharing key is problematic and became the impetus for the evolution of asymmetric
cryptography. The number of keys needed for n number of parties in the group is calculated
using the formula (n2 - n)/2. Thus, for an organization with 500 employees who
communicate with each other using encrypted e-mail, the number of keys is 1,24,750. The
key-management, therefore, gets obviously challenging with growing/large number of
employees.
 Difficult to establish responsibility in case of shared-key compromise, or
 The sender denies for sending an encrypted message
7
5.2 Asymmetric Cryptography
Asymmetric cryptography uses two different keys for encryption and decryption processes where
every user has his/h pair of keys termed as a public and a private key. The private key, known only
to the user, is kept secret throughout whereas the key called ‘public key’ is made publically known.
Data encrypted with a public key is decryptable only with the corresponding private key. Hence,
anyone wanting to communicate with the other (say Alice wants to communicate with Bob) must
use the recipient's public key to encrypt and send the secret message. Only the recipient can then
decrypt the message, using his/her private key. Likewise, data encrypted using a private key can
only get decrypted with the corresponding public key, a technique commonly employed to digitally
sign a message to confirm the genuineness of its sender (called non-repudiation).
Figure 2 is the graphical representation of the asymmetric process where Alice (the sender)
communicates with Bob (the recipient) using Bob’s public key.
Figure 2. Asymmetric Cryptography
Examples
RSA, Diffie-Helman, El-Gamal and such similar algorithms/protocols
5.2.1 Advantages
Asymmetric key cryptography:
 Solves the key-exchange problem
 Based on trivial mathematical phenomena
 Non-repudiation that is sender cannot deny of not sending the message (digital signatures)
5.2.2 Limitation
 Computational intensive
 With the introduction of Quantum computers, even 2048 bit keys (of RSA) are less likely
to offer resistance towards cracking
 Managing public keys of 500 people in a group may not seem a problem at a glance.
However, the problem raises too many folds as the number of people in a group/groups
increases. The Public Key Infrastructure (PKI) resolves that issue whose elaboration is
beyond the scope of this project.
6. Applications:
Cryptography has rigorous use in:
i) (e-)electronic commerce
8
ii) chip-based payment cards
iii) digital currencies
iv) computer passwords, and in civil and military communications
7. Some Mathematical Concepts
Before discussing RSA, it is necessary to understand a few mathematical concepts as follows:
7.1 Prime Numbers
Numbers whose only divisors include 1 and the number itself are called Prime numbers. For
example P = {2, 3, 5, 7, 11, …}
7.2 Multiplicative Inverse
A multiplicative inverse for a number x is that number which when multiplied by x-1
gives 1.
That is :
X. X-1
= 1 … … (3)
7.3 The Greatest Common Divisor
The greatest common divisor (gcd) of two numbers is the largest integer that evenly divides both
those numbers. For example:
gcd(4, 10) = 2 … … (4)
It is because 4 has factors 4 = 2 x 2 x 50
, while 10 can be factored as 10 = 2 x 5. By taking and
multiplying the least powered factors, we have 2 x 50
= 2.
It is interesting to see that if two numbers have a gcd of 1, then the smallest of the two has a
multiplicative inverse in the modulo (remainder) of the more substantial number. For example:
gcd(4, 9) = 1 … … (5)
Since, 4 = 2 x 2 x 30
, and 9 = 20
x 3 x 3. Hence, the inverse of 4 in modulo 9 exist which is
computed using a recursive formula:
gcd(x, y) = gcd(y, x mod y) or
9 = 2 x 4 + 1
1 = 9 – (2 x 4)
1 = (1) x 9 + (-2) x 4, and because
-2 ≡ 7 mod 9 … … (6)
Hence, the multiplicative inverse of 4 in modulo 9 is 7. But not all the primes have their
multiplicative inverse in a given modulo, such as 3, whose multiplicative inverse in modulo 9 does
not exist. That is:
gcd(3, 9) = 3, 𝑏𝑢𝑡 ≠ 1 … … (7)
9
7.4 Euler's Totient
It is the number of elements whose multiplicative inverse exist in a set of modulo numerals. The
‘totient’ is denoted using the Greek symbol phi ∅. In other words, it gives the count of the number
of elements that have their gcd with the given modulus equal to 1. Hence, this leads us to an
essential equation apropos the totient and prime numbers as follows:
𝑝 ∈ 𝑃, ∅(𝑝) = 𝑝 − 1 … … (8)
, where p is a prime number.
8. How RSA Works
With the preliminary concepts, it is now easy to understand ‘How RSA Works.’ Perform the
following steps/computations:
1) Select/generate two Large Prime Numbers (say) p and q with p < q and almost similar in
length regarding bits
2) Compute a modulus N from the two large numbers by multiplying p and q. That is, N = p
x q
3) Calculate the Euler’s totient of N. That is, ∅(𝑁) = (p -1) x (q - 1)
4) Public Key (e): Determine a prime number from the range [3, ∅(𝑁)) that has a greatest
common divisor of 1 with ∅(𝑁). Remember the public key is comprised of both e and 𝑵.
Typically, the prime is selected as 65537. Also, 1 < 𝑒 < ∅(𝑁), and e should be co-prime
with both N and ∅(𝑁).
https://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent-of-65537
5) Private Key (d): Compute the private key (d) using the formula:
(𝑒 . 𝑑) 𝑀𝑜𝑑 ∅(𝑁) ≡ 1 … … (9)
6) Translate alphabets/symbols to numbers and then encrypt those using the public key of the
recipient by the formula:
𝐶 = 𝑀 𝑒
𝑀𝑜𝑑 N … … (10)
Note: Extended Euclidean algorithm can also be used to find the multiplicative inverse
(d) of e reduced to modulo N.
7) The recipient using his/her private key will decrypt the encrypted numerals using the
formula:
𝑀′
= 𝐶 𝑑
𝑀𝑜𝑑 𝑁 … … (11)
, and translate the numbers to their corresponding alphabets/symbols accordingly to read/get
the message.
Remember: The resulting numerals after converting alphas/symbols must be less than the
modulus.
8.1 Working Example
1) Let p = 2, and q = 7, then N = p x q = 2 x 7 = 14. Let the number to be encrypted M = 11
2) ∅(14) = ∅(2) 𝑥 ∅(7) = (2 − 1)𝑥 (7 − 1) = 6, which implies that there are six numbers
in the range 1 to N - 1 that have a multiplicative inverse when reduced to modulo 14. Let
us write down all the numbers in that range. That is n = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
10
13}. It is apparent that 2, 4, 6, 7, 8, 10, and 12 have common factors with (N = ) 14. So the
reduced set is comprised of the elements n = {1, 3, 5, 9, 11, 13} (that is, six elements in
total)
3) 1 obviously is not a right choice, and so is 3 which is not coprime with ∅(14) = 6. Any
number ≥ 6 is also not the right choice because 1 < 𝑒 < ∅(𝑁). So the left over choice e
= 5 is our public key
4) Computing (5 x d) mod 6 ≡ 1 => d = 5, 11, …. Since, p should be less than q, so we take
11 as the private key
5) Encryption: From equation (10) we have … 𝐶 = 𝑀 𝑒
𝑀𝑜𝑑 N = 115
Mod 14 = 9
6) Decryption: From equation (11) we have … 𝑀′
= 𝐶 𝑑
𝑀𝑜𝑑 𝑁 = 911
Mod 14 = 11 (= M)
9. The Problem
Integer Factorization as regards number theory is the disintegration of a composite number into an
artifact of smaller integers which if further are circumscribed to prime numbers refers to the
process called prime factorization. However, any proficient, and non-quantum integer factorization
algorithm to process adequately large numbers is yet made publically available. Many researchers
in their attempt to factor a 232-digit number (RSA-768) utilizing hundreds of machines that took
them two years appraised in 2009 that a 1024-bit RSA modulus may take about a thousand times
longer. Table 2, however, depicts a different situation which reports factorization of 1856 bits long
number with 2009 (or earlier) computational resource.
Table 2: RSA Factorization for Different Length Prime Numbers
http://mathworld.wolfram.com/RSANumber.html
11
With today’s technology and immense computational power that machines have, a 2048 bit RSA
seems inadequately to provide secrecy. Hence, the presumed difficulty of factorization problem
which is at the heart of widely used cryptographic algorithm such as RSA remains at the stack and
needs a patch.
10. The Problem Statement
With today's high-speed computation intensive machines, the cryptographic protocol based on the
difficulty of large primes factorization such as RSA (and other related algorithms as such), would
render RSA-based public-key cryptography insecure.
11. Proposed Solution
One way to make RSA cracking trivial is to re-encrypt the output of RSA seamlessly (yet
revertable by those who possess the key) so that the encrypted contents remain gibberish just in
case the malicious attacker succeeds in factorizing N, from (e, N) the RSA public key. The concept
of re-encrypting an encrypted content with different keys has its implementation and support in
cryptography such as Tripple Data Encryption Standard (3DES). The significance, however, lies
in whether the encryption function forms an algebraic group under functional alignment. In other
words, the significance lies in the fact as to whether for any encryption function 𝐹𝑒() and keys 𝐾𝑖
applied to a message M, does 𝐹𝑒 ( 𝐾1, 𝐹𝑒 ( 𝐾2, M)) yields the same cryptogram as for 𝐹𝑒 ( 𝐾3, M )
for some 𝐾3? For example, the transposition cipher "rotate by 13 places", gives the same message
when applied twice. Using DES twice with different keys, however, has the effect of a larger
keyspace thus making the task of an attacker trifling.
On the above-referred analogy, we proposed re-encrypting RSA with a columnar transposition key
of varying length (within confines of the encrypted contents) that also varies from one message to
another, that is, using a unique transposition key for every (even same) message.
For quick and speedy demonstration, we have hardcoded the transposition key (Section 4.1.1
refers). In actual usage, the user may provide the transposition key as input or feed it in from a file
along with the message.
12. Implementation Details
The proposed concept is materialized using python 3.(+) version with Pycharm IDE. The program
first generates two large prime numbers in the range 256, 512, 1024, 2048 bits or a multiple
(regarding N = p x q) taken as input from the user along with the message for encryption. It then
tests those numbers for primality using Miller-Rabin test for primality. After that, it computes N,
∅(𝑁), e, d as stated in preceding relevent discussion. Next, the program publishes the ciphered
text along with the public, and private key-pair, which is followed by its decryption (remember all
this is done for instant verification and materialization of the concept).
13. The Source Code
Below is the Python implementation of the hybrid algorithm.
12
13.1 Encryption
The message gets processed through RSA. The output from RSA gets transposed using a key
comprising of eight non-repeated digits between 1 and eight as per procedure explained in the
relevant section. The result is the cryptogram/ciphered text.
13.2 Decryption
The input to the algorithm is first reversed-transposed using a key comprising of eight non-
repeated digits between 1 and eight as per procedure explained in the relevant section. The result
then gets processed through RSA which renders the message.
import random
from random import randrange, getrandbits
from math import log10
from time import time
from functools import reduce
from itertools import repeat
#
# FRSA
# No Implicit or Explicit Warranties
# The source code to be used at your own RISK
# Credits:
# KHAN FARHAN RAFAT
# e-mail: ubiquitousorpervasive@gmail.com
#
def mInverse(p, q):
def xgcd(xP, yP):
#Extended Euclidean Algorithm
seed1, seed0 = 0, 1
t1, t0 = 1, 0
while yP:
q = xP // yP
xP, yP = yP, xP % yP
seed1, seed0 = seed0 - q * seed1, seed1
t1, t0 = t0 - q * t1, t1
return xP, seed0, t0
sP, tP = xgcd(p, q)[0:2]
assert sP == 1
if tP < 0:
tP += q
return tP
def genPrime(nP):
def isPrime(nP, t=7):
def ifComposite(aP):
if pow(aP, dP, nP) == 1:
return False
for i in range(s):
if pow(aP, 2 ** i * dP, nP) == nP - 1:
return False
return True
assert nP > 0
13
if nP < 3:
return [False, False, True][nP]
elif not nP & 1:
return False
else:
s, dP = 0, nP - 1
while not dP & 1:
s += 1
dP >>= 1
for _ in repeat(None, t):
if ifComposite(randrange(2, n)):
return False
return True
p = getrandbits(n)
while not isPrime(p):
p = getrandbits(n)
return p
# https://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent-
of-65537
def genRSA(p, q):
phie, n = (p - 1) * (q - 1), p * q
if n < 65537:
return (3, mInverse(3, phie), n)
else:
return (65537, mInverse(65537, phie), n)
def t2i(text):
return reduce(lambda x, y: (x << 8) + y, map(ord, text))
def i2t(number, size):
text = "".join([chr((number >> j) & 0xff)
for j in reversed(range(0, size << 3, 8))])
return text.lstrip("x00")
def i2l(number, size):
return [(number >> j) & 0xff
for j in reversed(range(0, size << 3, 8))]
def l2i(listInt):
return reduce(lambda x, y: (x << 8) + y, listInt)
def sizeofModulous(mod):
sizeofModulous = len("{:02x}".format(mod)) // 2
return sizeofModulous
def encryptIt(ptext, pk, mod):
size = sizeofModulous(mod)
output = []
while ptext:
nbytes = min(len(ptext), size - 1)
14
aux1 = t2i(ptext[:nbytes])
assert aux1 < mod
aux2 = pow(aux1, pk, mod)
output += i2l(aux2, size + 2)
ptext = ptext[size:]
return output
def decryptIt(ctext, sk, p, q):
mod = p * q
size = sizeofModulous(mod)
output = ""
while ctext:
auxP = l2i(ctext[:size + 2])
assert auxP < mod
m1 = pow(auxP, sk % (p - 1), p)
m2 = pow(auxP, sk % (q - 1), q)
hP = (mInverse(q, p) * (m1 - m2)) % p
aux4 = m2 + hP * q
output += i2t(aux4, size)
ctext = ctext[size + 2:]
return output
def transP(matrix, words):
cipher = ''
lent = len(matrix)
blanks = ''.join(' ' for i in range(lent - 1))
for x in range(0, len(words), lent):
# todo optimization
item = words[x: x + lent] + blanks
for pos in matrix:
cipher += item[pos - 1]
return cipher
def rotaTe(matrix):
length = len(matrix)
arr = [0] * length
for i in range(length):
arr[matrix[i] - 1] = i + 1
return arr
def printHexList(intList):
for index, elem in enumerate(intList):
if index % 32 == 0:
print()
print("{:02x}".format(elem), end="")
print()
def printLargeInteger(number):
string = "{:02x}".format(number)
for jP in range(len(string)):
if jP % 64 == 0:
print()
print(string[jP], end="")
print()
15
def useCase(p, q, msg):
#print("Computed Key size is : {:0d} bits".format(round(log10(p * q) / log10(2))))
pk, sk, mod = genRSA(p, q)
print("nPhi ",end="")
printLargeInteger(mod)
print("nNow Encrypting ... ... ...")
st = time()
cText = reduce(lambda string, item: string + chr(item), encryptIt(msg, pk, mod),
"")
print("nCiphertext: ")
print(cText)
matrix = [6, 2, 4, 1, 7, 3, 8, 5]
ciphertext = transP(matrix, cText)
print("nTransposed String:n", end="")
print(ciphertext)
en = time()
print("Encryption took ", end="")
print("({:0.3f}) seconds".format(round(en - st, 3)))
print("-------------------------------")
print("nNow Decrypting ... ... ...")
st = time()
secret = rotaTe(matrix)
cText=transP(secret, ciphertext).strip()
print("nReversed Transposition n", cText)
k = []
for c in cText:
k.append(ord(c))
cText = k
pText = decryptIt(cText, sk, p, q)
en = time()
print("nDecrypted Text:", pText)
print("nDecryption took ", end="")
print("({:0.3f}) seconds".format(round(en - st, 3)))
print("-------------------------------")
if __name__ == "__main__":
Message=input("Type in your Message! : ")
n=int(input("Enter Length (in bits) for generating Primes p and q ! (256, 512,
1024, 2048) : "))
st = time()
p = genPrime(n)
q = genPrime(n)
en = time()
print("nPrime (p): ", end="")
printLargeInteger(p)
print("nPrime (q): ", end="")
printLargeInteger(q)
print("nTime elapsed in generating {:0d}-bit prime = ".format(n), end="")
print("({:0.3f}) seconds".format(round(en - st, 3)))
print("----------------------------------------------------------")
useCase(p, q, Message)
16
14. Program Generated Output
Following is the result of one of the execution of the source code:
C:UsersStud3ntAppDataLocalProgramsPythonPython36python.exe C:/Users/Stud3nt/.PyCharmCE2017.2/config/scratches/scratch_2.py
Type in your Message! : Allah O Akbar
Enter Length (in bits) for generating Primes p and q ! (256, 512, 1024, 2048) : 2048
Prime (p):
91dc6f5abd89e7d12459a9282746da3b38186fa29f327acaee9f575b8c0c4b97
ac096d2f1c398a30d71c580d88a213a41a17a28598f45fc348f4a997a2b0c414
5956e73940179e1e49543a5acb7c8115f87bfc6f8b0f67955ab80e689c22aa76
e2b76efad5c49a97f5039f411520380a2a07bdeafe5b1784a48437f6176caa52
f9ea962ba29ecffd9be6e7d05ddbc5a40f60efef417586a0732b02d40e4c799e
2132087aae23a9c66a8d8bbd7cb6c7a03416e79d5572dbe465c663b8c44d622f
6421f6cfb8ab10e6dd84173966228539c5b774f5fe51d52882a725d091feb533
c055fb81edcafdf4b9968b9e8cc598149454332af1aeead2c1b242dae64ff6b
Prime (q):
fca63733cb1c7054bf6edd13878910d2c442d33cd16455795ae0c21886f898aa
67ffc1b51aec1d0e66f9a2c02a074f256a62d3c02f4274bcf631cd292e60aad3
f40bdd7af03612b72ea7c87fb27eec8d910bf0e7a8617c4e7baf2531b87ab179
55dedacbfb31ebc86ccd7af1fbb9491dfd2ed9380c0709767aaacb59240db301
d1be14cc01ad71fc323c95fafbb402c31eb1e5fd36e4524ab05e98e2a54b57fd
b4bdc24cc71d97252cf99c645abebb2a6549ec33d51170fb6ea1d90ef0dabc14
971832b5ffb0bcc11a0cb5dd8ce52f7bcd36d8a324e8729eb2b54f18b871e6e6
62ff755f5d90d64563419611710759aabdcf78c5f96bbf6adf421bbef5ad1ee9
Time elapsed in generating 2048-bit prime = (43.363) seconds
---------------------------------------------------------------------------
Phi
8ff3b20165fb55d47104e67e6a6473856c0c772751e785cb4158d8163badf689
a12eb97d42fa02125d4ceff4bcfbd94a6ab1644d2b3fc3e9b165116840d0ad23
608006de3d5056084088836d8179f71ad5a684183d3dc8bead36ba426e9ec5f9
0f9b6ca4d5644ac8cce5941954dcbebf544188fa44b82f7a56d5a7fbec06043e
118567dee0d9e503289f6b6e627c900c2eb3a804929645581e1a7670f05ba83c
3eb90c3a51ccce35dcc28d14e0c0558cac2690d6b5514d6e310047990a12d3c0
c75a4bfaa949f53f68c10e9207557b5a992cd8ef59a61aa1312fc93c8688129b
19647415afd60bb68d5b50b8146d08a4c8586627ae8d737cef3fe5024204e16a
923dbc18e40632fcf733ff7a828f4d5a94da4c6a6b308c95fc7191f311a8df91
e71cb6612e6dbe74f1b2b98540c706ec3ea9cce99a7be7245eac103e5fc948bb
12db134c3e1416b22880f57b3a4394d8b0616619a46819907af4982b5ff2eb99
764d1073fd70cf0ca296b3ca9bb2f03d6c68e67061d12d361484a51a34d9480b
f746fea9fa9e3a2fe9f33a7dd26a3c75a212477811fc544f86fd797e781784ba
167e51105ada5e7d8afb9bf73db79ad2992d163044a47f5daf45d7d74ea881b8
0fc5be8b6fa33318f8e660d26fe4b5a50db7fd350637c8ca433f64b91556b7e0
1924cf6a120a445fd76c385c7e5bfa60ae486faaa7a81e1a232a51f922a0263
Now Encrypting ... ... ...
Ciphertext:
½ÄšNµlÈühd,ЈÂYiÛl×´ÙÄÅ€<$Ñ÷·˜A€F ¯¢9á€QS à†Ó¡5§
­•• †”go%­)dkVhÿx*E4ùŸoL5UÛ¹
dœzö:“läÝpЀ¨[‘Pd¤.O`?i±ƒå?#‡Ï:EÊr Zº}΄y€`8ß›PÎ
™>ð07
¿6wvä5íÄY§-Ç-ëƒu¨é•-õÖ÷³‘mU]ªëA39€†v1ùPF~gá¡$Gå89|7Sµ8ïÄá€Êƒt€(H@²Œ„_¦h¯NY"‰‡ÕT•ðû÷o(ÜÊ"^,S4)=«$ 8Â-…ä…S-
fR÷âÔ•á•–^}ƒÿAÑ-ý7=áƒE?²¡€$°Úqy.HÂE¨¿´õý„ÉšXBô:/= óz‡µ îÕŠ’óÔæ—¼/[
Transposed Ciphered Text:
þ Ä €½HùüNlšhµdÈYÐ,iˆÂÙlÛÄ×´Ñ<Å÷€·$¯AF˜¢€9 à€Sá†QÓ Ï5
• ­%”†g­oÿdV)xk*hL4ŸEù5oœÛ
Uz¹dÝ:löp“Ðäd¨‘€¤[.P±?Oƒ`åiE#Ï?ʇr:„Z} yºÎ›•8 P`Îß7™ð
>056v¿íwÄä-Y-§ëÇ•uƒ¨-é«÷Ö³]‘Uªm€A3ë†v9~1PùgFå¡á8$9G87|ïSĵ€€ƒá(ÊHt¦²„@hŒ_‡N"¯ÕYT‰(ð÷•ÜûÊo)^S"=,«4 $-…8R…-
ä÷Sâf–áÔ^€}€ýÿу7A=-ƒ?á¡E€².°q$HÚÂyý¨´E„¿Éõ/Xôš=B :îzµóÕ‡Š ¼óæ’/Ô[—
17
Encryption took (0.016) seconds
----------------------------------------
Now Decrypting ... ... ...
Reversed Transposition
½ÄšNµlÈühd,ЈÂYiÛl×´ÙÄÅ€<$Ñ÷·˜A€F ¯¢9á€QS à†Ó¡5§
­•• †”go%­)dkVhÿx*E4ùŸoL5UÛ¹
dœzö:“läÝpЀ¨[‘Pd¤.O`?i±ƒå?#‡Ï:EÊr Zº}΄y€`8ß›PÎ
™>ð07
¿6wvä5íÄY§-Ç-ëƒu¨é•-õÖ÷³‘mU]ªëA39€†v1ùPF~gá¡$Gå89|7Sµ8ïÄá•Êƒt€(H@²Œ„_¦h¯NY"‰‡ÕT•ðû÷o(ÜÊ"^,S4)=«$ 8Â-…ä…S-
fR÷âÔ•á•–^}ƒÿAÑ-ý7=áƒE?²¡€$°Úqy.HÂE¨¿´õý„ÉšXBô:/= óz‡µ îÕŠ’óÔæ—¼/[
Decrypted Text: Allah O Akbar
Decryption took (0.063) seconds
---------------------------------------
Process finished with exit code 0
15. Screenshot
Following is the screenshot of the output:
16. Advantages
Following are some of the advantages of the proposed enhancement:
 Increased difficulty level towards deriving the prime factors of “n”
 Key-dependent transposition of ciphered text will entail enemy efforts towards cracking it
17. Future Work
Following are suggested as future work:
18
 Evolution and implementation of an indigenous Random Number Generator (RNG),
preferably Hardware Based.
 Key-dependent Generation of the Transposition Key with varied length >= 8
Reference
Following are some of the references used:
https://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent-of-
65537
https://www.gronau-it-cloud-computing.de/en/cryptographic-key-length-recommendation-
from-organizations/

More Related Content

What's hot

Bt0088 cryptography and network security2
Bt0088 cryptography and network security2Bt0088 cryptography and network security2
Bt0088 cryptography and network security2Techglyphs
 
Network security & cryptography full notes
Network security & cryptography full notesNetwork security & cryptography full notes
Network security & cryptography full notesgangadhar9989166446
 
6. cryptography
6. cryptography6. cryptography
6. cryptography7wounders
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network securityshraddha mane
 
Advanced cryptography and implementation
Advanced cryptography and implementationAdvanced cryptography and implementation
Advanced cryptography and implementationAkash Jadhav
 
Information Security & Cryptography
Information Security & CryptographyInformation Security & Cryptography
Information Security & CryptographyArun ACE
 
PROJECT REPORT ON CRYPTOGRAPHIC ALGORITHM
PROJECT REPORT ON CRYPTOGRAPHIC ALGORITHMPROJECT REPORT ON CRYPTOGRAPHIC ALGORITHM
PROJECT REPORT ON CRYPTOGRAPHIC ALGORITHMsaniacorreya
 
Security services and mechanisms
Security services and mechanismsSecurity services and mechanisms
Security services and mechanismsRajapriya82
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptographyVaibhav Khanna
 
Ch01
Ch01Ch01
Ch01n C
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYKathirvel Ayyaswamy
 

What's hot (20)

Bt0088 cryptography and network security2
Bt0088 cryptography and network security2Bt0088 cryptography and network security2
Bt0088 cryptography and network security2
 
Network security & cryptography full notes
Network security & cryptography full notesNetwork security & cryptography full notes
Network security & cryptography full notes
 
6. cryptography
6. cryptography6. cryptography
6. cryptography
 
Info security & crypto
Info security & cryptoInfo security & crypto
Info security & crypto
 
Cryptography ppt
Cryptography pptCryptography ppt
Cryptography ppt
 
Networksecurity1 1
Networksecurity1 1 Networksecurity1 1
Networksecurity1 1
 
Cryptography
CryptographyCryptography
Cryptography
 
Cryptography for Everyone
Cryptography for EveryoneCryptography for Everyone
Cryptography for Everyone
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 
Overview of cryptography
Overview of cryptographyOverview of cryptography
Overview of cryptography
 
Advanced cryptography and implementation
Advanced cryptography and implementationAdvanced cryptography and implementation
Advanced cryptography and implementation
 
Information Security & Cryptography
Information Security & CryptographyInformation Security & Cryptography
Information Security & Cryptography
 
PROJECT REPORT ON CRYPTOGRAPHIC ALGORITHM
PROJECT REPORT ON CRYPTOGRAPHIC ALGORITHMPROJECT REPORT ON CRYPTOGRAPHIC ALGORITHM
PROJECT REPORT ON CRYPTOGRAPHIC ALGORITHM
 
Security services and mechanisms
Security services and mechanismsSecurity services and mechanisms
Security services and mechanisms
 
Cryptography.ppt
Cryptography.pptCryptography.ppt
Cryptography.ppt
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptography
 
Cryptography
Cryptography Cryptography
Cryptography
 
Ch01
Ch01Ch01
Ch01
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
 
Cryptography
CryptographyCryptography
Cryptography
 

Similar to Frsa

online game over cryptography
online game over cryptographyonline game over cryptography
online game over cryptographyAshish Kumar
 
Cryptography And Embedded Systems Used
Cryptography And Embedded Systems UsedCryptography And Embedded Systems Used
Cryptography And Embedded Systems UsedCarla Bennington
 
Chapter 8Secure Transport LayerIn the early days of th
Chapter 8Secure Transport LayerIn the early days of thChapter 8Secure Transport LayerIn the early days of th
Chapter 8Secure Transport LayerIn the early days of thJinElias52
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptographyPavithra renu
 
E-commerce- Security & Encryption
E-commerce- Security & EncryptionE-commerce- Security & Encryption
E-commerce- Security & EncryptionBiroja
 
Nt1310 Unit 6 Powerpoint
Nt1310 Unit 6 PowerpointNt1310 Unit 6 Powerpoint
Nt1310 Unit 6 PowerpointJanet Robinson
 
fundamental of network security
fundamental of network securityfundamental of network security
fundamental of network securityManish Tiwari
 
HYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTS
HYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTSHYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTS
HYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTSIJNSA Journal
 
Achieving data integrity by forming the digital signature using RSA and SHA-1...
Achieving data integrity by forming the digital signature using RSA and SHA-1...Achieving data integrity by forming the digital signature using RSA and SHA-1...
Achieving data integrity by forming the digital signature using RSA and SHA-1...IOSR Journals
 
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...IOSR Journals
 
VULNERABILITIES OF THE SSL/TLS PROTOCOL
VULNERABILITIES OF THE SSL/TLS PROTOCOLVULNERABILITIES OF THE SSL/TLS PROTOCOL
VULNERABILITIES OF THE SSL/TLS PROTOCOLcscpconf
 
Vulnerabilities of the SSL/TLS Protocol
Vulnerabilities of the SSL/TLS ProtocolVulnerabilities of the SSL/TLS Protocol
Vulnerabilities of the SSL/TLS Protocolcsandit
 
Introduction to Network Security
Introduction to Network SecurityIntroduction to Network Security
Introduction to Network SecurityShitiz Upreti
 
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATIONENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATIONIJNSA Journal
 

Similar to Frsa (20)

online game over cryptography
online game over cryptographyonline game over cryptography
online game over cryptography
 
Cryptography And Embedded Systems Used
Cryptography And Embedded Systems UsedCryptography And Embedded Systems Used
Cryptography And Embedded Systems Used
 
Chapter 8Secure Transport LayerIn the early days of th
Chapter 8Secure Transport LayerIn the early days of thChapter 8Secure Transport LayerIn the early days of th
Chapter 8Secure Transport LayerIn the early days of th
 
Cryptography
CryptographyCryptography
Cryptography
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptography
 
E-commerce- Security & Encryption
E-commerce- Security & EncryptionE-commerce- Security & Encryption
E-commerce- Security & Encryption
 
Nt1310 Unit 6 Powerpoint
Nt1310 Unit 6 PowerpointNt1310 Unit 6 Powerpoint
Nt1310 Unit 6 Powerpoint
 
fundamental of network security
fundamental of network securityfundamental of network security
fundamental of network security
 
security issue
security issuesecurity issue
security issue
 
Module 2.pdf
Module 2.pdfModule 2.pdf
Module 2.pdf
 
Module 2.Cryptography and Cryptanalysis
Module 2.Cryptography and CryptanalysisModule 2.Cryptography and Cryptanalysis
Module 2.Cryptography and Cryptanalysis
 
HYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTS
HYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTSHYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTS
HYBRID CRYPTOGRAPHIC TECHNIQUE USING RSA ALGORITHM AND SCHEDULING CONCEPTS
 
A New Design of Algorithm for Enhancing Security in Bluetooth Communication w...
A New Design of Algorithm for Enhancing Security in Bluetooth Communication w...A New Design of Algorithm for Enhancing Security in Bluetooth Communication w...
A New Design of Algorithm for Enhancing Security in Bluetooth Communication w...
 
Achieving data integrity by forming the digital signature using RSA and SHA-1...
Achieving data integrity by forming the digital signature using RSA and SHA-1...Achieving data integrity by forming the digital signature using RSA and SHA-1...
Achieving data integrity by forming the digital signature using RSA and SHA-1...
 
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
Generate an Encryption Key by using Biometric Cryptosystems to secure transfe...
 
Sw week12
Sw week12Sw week12
Sw week12
 
VULNERABILITIES OF THE SSL/TLS PROTOCOL
VULNERABILITIES OF THE SSL/TLS PROTOCOLVULNERABILITIES OF THE SSL/TLS PROTOCOL
VULNERABILITIES OF THE SSL/TLS PROTOCOL
 
Vulnerabilities of the SSL/TLS Protocol
Vulnerabilities of the SSL/TLS ProtocolVulnerabilities of the SSL/TLS Protocol
Vulnerabilities of the SSL/TLS Protocol
 
Introduction to Network Security
Introduction to Network SecurityIntroduction to Network Security
Introduction to Network Security
 
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATIONENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
ENHANCED SECURE ALGORITHM FOR MESSAGE COMMUNICATION
 

Recently uploaded

KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 

Recently uploaded (20)

KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 

Frsa

  • 1. RSA WITH WEAK KEYS Dedicated to Rivest, Shamir and Adleman CORE ISSUE With today's high-speed computation intensive machines, the cryptographic protocol based on the difficulty of large primes factorization such as RSA (and other related algorithms as such), would render RSA-based public-key cryptography insecure. Khan Farhan Rafat Programming for Security Professionals
  • 2. 1 Contents 1. Types of Attack on any Network/Communication.................................................................. 3 1.1 Passive Attacks ..................................................................................................................... 3 1.2 Active Attacks....................................................................................................................... 3 2. Cryptography........................................................................................................................... 3 2.1 Encryption............................................................................................................................. 3 2.2 Decryption............................................................................................................................. 3 3. Why Cryptography .................................................................................................................. 3 4. Cryptographic Techniques / Types of Ciphers........................................................................ 4 4.1 Transposition......................................................................................................................... 4 4.1.1 Encipher......................................................................................................................... 4 4.1.2 Decipher......................................................................................................................... 5 4.2 Substitution ........................................................................................................................... 5 4.2.1 Morse Code.................................................................................................................... 5 5. Types of Cryptography ........................................................................................................... 5 5.1 Symmetric Cryptography................................................................................................. 6 Examples................................................................................................................................. 6 5.1.1 Advantages......................................................................................................................... 6 5.1.2 Limitation........................................................................................................................... 6 5.2 Asymmetric Cryptography.................................................................................................... 7 Examples................................................................................................................................. 7 5.2.1 Advantages......................................................................................................................... 7 5.2.2 Limitation........................................................................................................................... 7 6. Applications:........................................................................................................................... 7 7. Some Mathematical Concepts................................................................................................. 8 7.1 Prime Numbers ..................................................................................................................... 8 7.2 Multiplicative Inverse........................................................................................................... 8 7.3 The Greatest Common Divisor............................................................................................. 8 7.4 Euler's Totient....................................................................................................................... 9 8. How RSA Works .................................................................................................................... 9 8.1 Working Example................................................................................................................. 9 9. The Problem.......................................................................................................................... 10
  • 3. 2 10. The Problem Statement...................................................................................................... 11 11. Proposed Solution.............................................................................................................. 11 12. Implementation Details...................................................................................................... 11 13. The Source Code................................................................................................................ 11 13.1 Encryption......................................................................................................................... 12 13.2 Decryption......................................................................................................................... 12 14. Program Generated Output ................................................................................................ 16 15. Screenshot.......................................................................................................................... 17 16. Advantages......................................................................................................................... 17 17. Future Work....................................................................................................................... 17 Reference ...................................................................................................................................... 18
  • 4. 3 1. Types of Attack on any Network/Communication The two main types of attacks that an adversary may launch on a network include: 1.1 Passive Attacks Passive attacks can be online where an attacker only tries to read/listen to a network segment for any subtle information as it travels across the network or offline in which an attacker extracts and stores real-time traffic for lateral views. 1.2 Active Attacks In this type of attack, a malicious attacker attempts in real time to satirize as a client or server to intercept the ongoing communication for modifying (to add and or delete/drop) the contents before letting these go to their intended destination. 2. Cryptography The word Cryptography or cryptology derived from the Greek words i) κρυπτός kryptós, which means "hidden, secret"; and ii) γράφειν “graphein,” meaning "writing," or -λογία -logia, "study," respectively). It is the modus operandi for secure communication in the perspective of eavesdroppers called adversaries. In general, cryptography deals with creating and evaluating protocols that prevent the unauthorized or the public from intruding into private or secret communication. Disciplines such as mathematics, computer science, communication science, electrical engineering, and physics are at the heart of Modern Cryptography. 2.1 Encryption It is the process of making a clear message (Plain Text) unintelligible (Ciphered text or Cryptogram) whose mathematical representation is as follows: 𝐸 𝑘(𝑀) = 𝐶 … … (1) Where E denotes the encryption algorithm that takes some input message M, operates upon it using some Key K to produce the ciphered message. 2.2 Decryption It takes a ciphered text and converts it into a readable form. The mathematical depiction of the process is as follows: Equation (1) => 𝐷 𝑘(𝐶) = 𝐷 𝑘(𝐸 𝑘(𝑀)) = M … … (2) Where D denotes the decryption algorithm that takes some input ciphered text C, operates upon it using some Key K to produce the message. 3. Why Cryptography Cryptography is the means by which communications gets protected over untrusted networks. Modern cryptography also focuses on other aspects of information security that includes:
  • 5. 4 i) data confidentiality ii) data integrity iii) authentication and iv) Non-Repudiation. Multiple endpoints regarding multiple clients and one or more back-end servers is often a salient trait of Software systems. However, the network such as the Internet, over which these client/ servers communicate cannot be trustworthy. The cryptographic protocols like SSL/TLS provide confidentiality and integrity protection to the contents that get exchanged online from tampering and eavesdropping. Authenticity ensures that actual users are communicating with the systems (HMAC, RSA encryption, and other such schemes). Protecting Data at rest: Cryptography is also employed to protect data at rest by encrypting the data resident on a removable disk or in a database to prevent unauthorized disclosure of sensitive data should the physical media gets lost or stolen. Likewise, it also provides integrity protection to detect malicious meddling of the data at rest. 4. Cryptographic Techniques / Types of Ciphers Since its inception, Cryptography makes use of the two techniques namely: 4.1 Transposition This technique intends to achieve secrecy by strewing the alphabets/words constituting a message. Following is one such way (employed in this report) of doing the transposition: 4.1.1 Encipher Let our Message be: a quick brown fox jumps over the lazy dog Arranging the message in a Matrix (? X 8 columns) form, using column Labels from the Secret Key (8) [6, 2, 4, 1, 7, 3, 8, 5] Taking out alphabets in increasing order using column labels from above Matrix gives the Cipher Text as: u cq aikwr oobnfu pj xmsrvteeo dzl ao dqdepmgcw 6 2 4 1 7 3 8 5 a q u i c k b r o w n f o x j u m p s o v e r t h e l a z y d o g d p q c e w m
  • 6. 5 4.1.2 Decipher Let the Ciphertext be: u cq aikwr oobnfu pj xmsrvteeo dzl ao dqdepmgcw Arranging the ciphered text in a Matrix (? X 8 columns) form, using column Labels from the Secret Key (8) [6, 2, 4, 1, 7, 3, 8, 5] Extracting the text row-wise gives the secret message: a quick brown fox jumps over the lazy dog after discarding the gibberish text. 4.2 Substitution This technique intends to achieve secrecy by replacing/substituting the alphabets/words constituting a message. Following serves as an example: 4.2.1 Morse Code developed for use by telegraph operators and first used for communication by Titanic is a well-known example of a substitution cipher. Here, the alphabets/letters in a message get replaced/substituted by dots and dashes. This code has an international adaptation. The Morse code for the international distress signal (SOS) is ... --- .... Table 1 shows the alphabets along with their respective Morse Codes. Table 1: Morse Code Representation (http://www-math.ucdenver.edu/~wcherowi/courses/m5410/m5410cc.html) 5. Types of Cryptography Computational hardness or trivial assumptions are critical to cryptographic algorithm design and development, which means that such algorithms are breakable in theory but infeasible to materialize by any well-known means. Examples include integer factorization algorithms (RSA 6 2 4 1 7 3 8 5 a q u i c k b r o w n f o x j u m p s o v e r t h e l a z y d o g d p q c e w m
  • 7. 6 algorithm) and discrete logarithms (Elgamal Key exchange protocol). However, there exist information-theoretically secure systems which stand unbroken even with unlimited computing power. The one-time pad (OTP) often quoted as an example of such type of system. Cryptography, in general, is classified into two categories: 5.1Symmetric Cryptography In symmetric cryptography, the sender and the receiver uses one shared (by some means) / pre- agreed key for both encryption and decryption. Figure 1 graphically illustrates the symmetric cryptography process. Figure 1. Symmetric Cryptography Remember that both sender and the receiver share and use the same key for encryption and decryption respectively. Examples Block Cypher [Advanced Encryption Standard (AES)], Stream Cyphers (CryptMT) 5.1.1 Advantages Symmetric key cryptography is:  Extremely fast  Can encrypt bulk of data (such as disk partition or the database) 5.1.2 Limitation  Sharing key is problematic and became the impetus for the evolution of asymmetric cryptography. The number of keys needed for n number of parties in the group is calculated using the formula (n2 - n)/2. Thus, for an organization with 500 employees who communicate with each other using encrypted e-mail, the number of keys is 1,24,750. The key-management, therefore, gets obviously challenging with growing/large number of employees.  Difficult to establish responsibility in case of shared-key compromise, or  The sender denies for sending an encrypted message
  • 8. 7 5.2 Asymmetric Cryptography Asymmetric cryptography uses two different keys for encryption and decryption processes where every user has his/h pair of keys termed as a public and a private key. The private key, known only to the user, is kept secret throughout whereas the key called ‘public key’ is made publically known. Data encrypted with a public key is decryptable only with the corresponding private key. Hence, anyone wanting to communicate with the other (say Alice wants to communicate with Bob) must use the recipient's public key to encrypt and send the secret message. Only the recipient can then decrypt the message, using his/her private key. Likewise, data encrypted using a private key can only get decrypted with the corresponding public key, a technique commonly employed to digitally sign a message to confirm the genuineness of its sender (called non-repudiation). Figure 2 is the graphical representation of the asymmetric process where Alice (the sender) communicates with Bob (the recipient) using Bob’s public key. Figure 2. Asymmetric Cryptography Examples RSA, Diffie-Helman, El-Gamal and such similar algorithms/protocols 5.2.1 Advantages Asymmetric key cryptography:  Solves the key-exchange problem  Based on trivial mathematical phenomena  Non-repudiation that is sender cannot deny of not sending the message (digital signatures) 5.2.2 Limitation  Computational intensive  With the introduction of Quantum computers, even 2048 bit keys (of RSA) are less likely to offer resistance towards cracking  Managing public keys of 500 people in a group may not seem a problem at a glance. However, the problem raises too many folds as the number of people in a group/groups increases. The Public Key Infrastructure (PKI) resolves that issue whose elaboration is beyond the scope of this project. 6. Applications: Cryptography has rigorous use in: i) (e-)electronic commerce
  • 9. 8 ii) chip-based payment cards iii) digital currencies iv) computer passwords, and in civil and military communications 7. Some Mathematical Concepts Before discussing RSA, it is necessary to understand a few mathematical concepts as follows: 7.1 Prime Numbers Numbers whose only divisors include 1 and the number itself are called Prime numbers. For example P = {2, 3, 5, 7, 11, …} 7.2 Multiplicative Inverse A multiplicative inverse for a number x is that number which when multiplied by x-1 gives 1. That is : X. X-1 = 1 … … (3) 7.3 The Greatest Common Divisor The greatest common divisor (gcd) of two numbers is the largest integer that evenly divides both those numbers. For example: gcd(4, 10) = 2 … … (4) It is because 4 has factors 4 = 2 x 2 x 50 , while 10 can be factored as 10 = 2 x 5. By taking and multiplying the least powered factors, we have 2 x 50 = 2. It is interesting to see that if two numbers have a gcd of 1, then the smallest of the two has a multiplicative inverse in the modulo (remainder) of the more substantial number. For example: gcd(4, 9) = 1 … … (5) Since, 4 = 2 x 2 x 30 , and 9 = 20 x 3 x 3. Hence, the inverse of 4 in modulo 9 exist which is computed using a recursive formula: gcd(x, y) = gcd(y, x mod y) or 9 = 2 x 4 + 1 1 = 9 – (2 x 4) 1 = (1) x 9 + (-2) x 4, and because -2 ≡ 7 mod 9 … … (6) Hence, the multiplicative inverse of 4 in modulo 9 is 7. But not all the primes have their multiplicative inverse in a given modulo, such as 3, whose multiplicative inverse in modulo 9 does not exist. That is: gcd(3, 9) = 3, 𝑏𝑢𝑡 ≠ 1 … … (7)
  • 10. 9 7.4 Euler's Totient It is the number of elements whose multiplicative inverse exist in a set of modulo numerals. The ‘totient’ is denoted using the Greek symbol phi ∅. In other words, it gives the count of the number of elements that have their gcd with the given modulus equal to 1. Hence, this leads us to an essential equation apropos the totient and prime numbers as follows: 𝑝 ∈ 𝑃, ∅(𝑝) = 𝑝 − 1 … … (8) , where p is a prime number. 8. How RSA Works With the preliminary concepts, it is now easy to understand ‘How RSA Works.’ Perform the following steps/computations: 1) Select/generate two Large Prime Numbers (say) p and q with p < q and almost similar in length regarding bits 2) Compute a modulus N from the two large numbers by multiplying p and q. That is, N = p x q 3) Calculate the Euler’s totient of N. That is, ∅(𝑁) = (p -1) x (q - 1) 4) Public Key (e): Determine a prime number from the range [3, ∅(𝑁)) that has a greatest common divisor of 1 with ∅(𝑁). Remember the public key is comprised of both e and 𝑵. Typically, the prime is selected as 65537. Also, 1 < 𝑒 < ∅(𝑁), and e should be co-prime with both N and ∅(𝑁). https://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent-of-65537 5) Private Key (d): Compute the private key (d) using the formula: (𝑒 . 𝑑) 𝑀𝑜𝑑 ∅(𝑁) ≡ 1 … … (9) 6) Translate alphabets/symbols to numbers and then encrypt those using the public key of the recipient by the formula: 𝐶 = 𝑀 𝑒 𝑀𝑜𝑑 N … … (10) Note: Extended Euclidean algorithm can also be used to find the multiplicative inverse (d) of e reduced to modulo N. 7) The recipient using his/her private key will decrypt the encrypted numerals using the formula: 𝑀′ = 𝐶 𝑑 𝑀𝑜𝑑 𝑁 … … (11) , and translate the numbers to their corresponding alphabets/symbols accordingly to read/get the message. Remember: The resulting numerals after converting alphas/symbols must be less than the modulus. 8.1 Working Example 1) Let p = 2, and q = 7, then N = p x q = 2 x 7 = 14. Let the number to be encrypted M = 11 2) ∅(14) = ∅(2) 𝑥 ∅(7) = (2 − 1)𝑥 (7 − 1) = 6, which implies that there are six numbers in the range 1 to N - 1 that have a multiplicative inverse when reduced to modulo 14. Let us write down all the numbers in that range. That is n = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  • 11. 10 13}. It is apparent that 2, 4, 6, 7, 8, 10, and 12 have common factors with (N = ) 14. So the reduced set is comprised of the elements n = {1, 3, 5, 9, 11, 13} (that is, six elements in total) 3) 1 obviously is not a right choice, and so is 3 which is not coprime with ∅(14) = 6. Any number ≥ 6 is also not the right choice because 1 < 𝑒 < ∅(𝑁). So the left over choice e = 5 is our public key 4) Computing (5 x d) mod 6 ≡ 1 => d = 5, 11, …. Since, p should be less than q, so we take 11 as the private key 5) Encryption: From equation (10) we have … 𝐶 = 𝑀 𝑒 𝑀𝑜𝑑 N = 115 Mod 14 = 9 6) Decryption: From equation (11) we have … 𝑀′ = 𝐶 𝑑 𝑀𝑜𝑑 𝑁 = 911 Mod 14 = 11 (= M) 9. The Problem Integer Factorization as regards number theory is the disintegration of a composite number into an artifact of smaller integers which if further are circumscribed to prime numbers refers to the process called prime factorization. However, any proficient, and non-quantum integer factorization algorithm to process adequately large numbers is yet made publically available. Many researchers in their attempt to factor a 232-digit number (RSA-768) utilizing hundreds of machines that took them two years appraised in 2009 that a 1024-bit RSA modulus may take about a thousand times longer. Table 2, however, depicts a different situation which reports factorization of 1856 bits long number with 2009 (or earlier) computational resource. Table 2: RSA Factorization for Different Length Prime Numbers http://mathworld.wolfram.com/RSANumber.html
  • 12. 11 With today’s technology and immense computational power that machines have, a 2048 bit RSA seems inadequately to provide secrecy. Hence, the presumed difficulty of factorization problem which is at the heart of widely used cryptographic algorithm such as RSA remains at the stack and needs a patch. 10. The Problem Statement With today's high-speed computation intensive machines, the cryptographic protocol based on the difficulty of large primes factorization such as RSA (and other related algorithms as such), would render RSA-based public-key cryptography insecure. 11. Proposed Solution One way to make RSA cracking trivial is to re-encrypt the output of RSA seamlessly (yet revertable by those who possess the key) so that the encrypted contents remain gibberish just in case the malicious attacker succeeds in factorizing N, from (e, N) the RSA public key. The concept of re-encrypting an encrypted content with different keys has its implementation and support in cryptography such as Tripple Data Encryption Standard (3DES). The significance, however, lies in whether the encryption function forms an algebraic group under functional alignment. In other words, the significance lies in the fact as to whether for any encryption function 𝐹𝑒() and keys 𝐾𝑖 applied to a message M, does 𝐹𝑒 ( 𝐾1, 𝐹𝑒 ( 𝐾2, M)) yields the same cryptogram as for 𝐹𝑒 ( 𝐾3, M ) for some 𝐾3? For example, the transposition cipher "rotate by 13 places", gives the same message when applied twice. Using DES twice with different keys, however, has the effect of a larger keyspace thus making the task of an attacker trifling. On the above-referred analogy, we proposed re-encrypting RSA with a columnar transposition key of varying length (within confines of the encrypted contents) that also varies from one message to another, that is, using a unique transposition key for every (even same) message. For quick and speedy demonstration, we have hardcoded the transposition key (Section 4.1.1 refers). In actual usage, the user may provide the transposition key as input or feed it in from a file along with the message. 12. Implementation Details The proposed concept is materialized using python 3.(+) version with Pycharm IDE. The program first generates two large prime numbers in the range 256, 512, 1024, 2048 bits or a multiple (regarding N = p x q) taken as input from the user along with the message for encryption. It then tests those numbers for primality using Miller-Rabin test for primality. After that, it computes N, ∅(𝑁), e, d as stated in preceding relevent discussion. Next, the program publishes the ciphered text along with the public, and private key-pair, which is followed by its decryption (remember all this is done for instant verification and materialization of the concept). 13. The Source Code Below is the Python implementation of the hybrid algorithm.
  • 13. 12 13.1 Encryption The message gets processed through RSA. The output from RSA gets transposed using a key comprising of eight non-repeated digits between 1 and eight as per procedure explained in the relevant section. The result is the cryptogram/ciphered text. 13.2 Decryption The input to the algorithm is first reversed-transposed using a key comprising of eight non- repeated digits between 1 and eight as per procedure explained in the relevant section. The result then gets processed through RSA which renders the message. import random from random import randrange, getrandbits from math import log10 from time import time from functools import reduce from itertools import repeat # # FRSA # No Implicit or Explicit Warranties # The source code to be used at your own RISK # Credits: # KHAN FARHAN RAFAT # e-mail: ubiquitousorpervasive@gmail.com # def mInverse(p, q): def xgcd(xP, yP): #Extended Euclidean Algorithm seed1, seed0 = 0, 1 t1, t0 = 1, 0 while yP: q = xP // yP xP, yP = yP, xP % yP seed1, seed0 = seed0 - q * seed1, seed1 t1, t0 = t0 - q * t1, t1 return xP, seed0, t0 sP, tP = xgcd(p, q)[0:2] assert sP == 1 if tP < 0: tP += q return tP def genPrime(nP): def isPrime(nP, t=7): def ifComposite(aP): if pow(aP, dP, nP) == 1: return False for i in range(s): if pow(aP, 2 ** i * dP, nP) == nP - 1: return False return True assert nP > 0
  • 14. 13 if nP < 3: return [False, False, True][nP] elif not nP & 1: return False else: s, dP = 0, nP - 1 while not dP & 1: s += 1 dP >>= 1 for _ in repeat(None, t): if ifComposite(randrange(2, n)): return False return True p = getrandbits(n) while not isPrime(p): p = getrandbits(n) return p # https://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent- of-65537 def genRSA(p, q): phie, n = (p - 1) * (q - 1), p * q if n < 65537: return (3, mInverse(3, phie), n) else: return (65537, mInverse(65537, phie), n) def t2i(text): return reduce(lambda x, y: (x << 8) + y, map(ord, text)) def i2t(number, size): text = "".join([chr((number >> j) & 0xff) for j in reversed(range(0, size << 3, 8))]) return text.lstrip("x00") def i2l(number, size): return [(number >> j) & 0xff for j in reversed(range(0, size << 3, 8))] def l2i(listInt): return reduce(lambda x, y: (x << 8) + y, listInt) def sizeofModulous(mod): sizeofModulous = len("{:02x}".format(mod)) // 2 return sizeofModulous def encryptIt(ptext, pk, mod): size = sizeofModulous(mod) output = [] while ptext: nbytes = min(len(ptext), size - 1)
  • 15. 14 aux1 = t2i(ptext[:nbytes]) assert aux1 < mod aux2 = pow(aux1, pk, mod) output += i2l(aux2, size + 2) ptext = ptext[size:] return output def decryptIt(ctext, sk, p, q): mod = p * q size = sizeofModulous(mod) output = "" while ctext: auxP = l2i(ctext[:size + 2]) assert auxP < mod m1 = pow(auxP, sk % (p - 1), p) m2 = pow(auxP, sk % (q - 1), q) hP = (mInverse(q, p) * (m1 - m2)) % p aux4 = m2 + hP * q output += i2t(aux4, size) ctext = ctext[size + 2:] return output def transP(matrix, words): cipher = '' lent = len(matrix) blanks = ''.join(' ' for i in range(lent - 1)) for x in range(0, len(words), lent): # todo optimization item = words[x: x + lent] + blanks for pos in matrix: cipher += item[pos - 1] return cipher def rotaTe(matrix): length = len(matrix) arr = [0] * length for i in range(length): arr[matrix[i] - 1] = i + 1 return arr def printHexList(intList): for index, elem in enumerate(intList): if index % 32 == 0: print() print("{:02x}".format(elem), end="") print() def printLargeInteger(number): string = "{:02x}".format(number) for jP in range(len(string)): if jP % 64 == 0: print() print(string[jP], end="") print()
  • 16. 15 def useCase(p, q, msg): #print("Computed Key size is : {:0d} bits".format(round(log10(p * q) / log10(2)))) pk, sk, mod = genRSA(p, q) print("nPhi ",end="") printLargeInteger(mod) print("nNow Encrypting ... ... ...") st = time() cText = reduce(lambda string, item: string + chr(item), encryptIt(msg, pk, mod), "") print("nCiphertext: ") print(cText) matrix = [6, 2, 4, 1, 7, 3, 8, 5] ciphertext = transP(matrix, cText) print("nTransposed String:n", end="") print(ciphertext) en = time() print("Encryption took ", end="") print("({:0.3f}) seconds".format(round(en - st, 3))) print("-------------------------------") print("nNow Decrypting ... ... ...") st = time() secret = rotaTe(matrix) cText=transP(secret, ciphertext).strip() print("nReversed Transposition n", cText) k = [] for c in cText: k.append(ord(c)) cText = k pText = decryptIt(cText, sk, p, q) en = time() print("nDecrypted Text:", pText) print("nDecryption took ", end="") print("({:0.3f}) seconds".format(round(en - st, 3))) print("-------------------------------") if __name__ == "__main__": Message=input("Type in your Message! : ") n=int(input("Enter Length (in bits) for generating Primes p and q ! (256, 512, 1024, 2048) : ")) st = time() p = genPrime(n) q = genPrime(n) en = time() print("nPrime (p): ", end="") printLargeInteger(p) print("nPrime (q): ", end="") printLargeInteger(q) print("nTime elapsed in generating {:0d}-bit prime = ".format(n), end="") print("({:0.3f}) seconds".format(round(en - st, 3))) print("----------------------------------------------------------") useCase(p, q, Message)
  • 17. 16 14. Program Generated Output Following is the result of one of the execution of the source code: C:UsersStud3ntAppDataLocalProgramsPythonPython36python.exe C:/Users/Stud3nt/.PyCharmCE2017.2/config/scratches/scratch_2.py Type in your Message! : Allah O Akbar Enter Length (in bits) for generating Primes p and q ! (256, 512, 1024, 2048) : 2048 Prime (p): 91dc6f5abd89e7d12459a9282746da3b38186fa29f327acaee9f575b8c0c4b97 ac096d2f1c398a30d71c580d88a213a41a17a28598f45fc348f4a997a2b0c414 5956e73940179e1e49543a5acb7c8115f87bfc6f8b0f67955ab80e689c22aa76 e2b76efad5c49a97f5039f411520380a2a07bdeafe5b1784a48437f6176caa52 f9ea962ba29ecffd9be6e7d05ddbc5a40f60efef417586a0732b02d40e4c799e 2132087aae23a9c66a8d8bbd7cb6c7a03416e79d5572dbe465c663b8c44d622f 6421f6cfb8ab10e6dd84173966228539c5b774f5fe51d52882a725d091feb533 c055fb81edcafdf4b9968b9e8cc598149454332af1aeead2c1b242dae64ff6b Prime (q): fca63733cb1c7054bf6edd13878910d2c442d33cd16455795ae0c21886f898aa 67ffc1b51aec1d0e66f9a2c02a074f256a62d3c02f4274bcf631cd292e60aad3 f40bdd7af03612b72ea7c87fb27eec8d910bf0e7a8617c4e7baf2531b87ab179 55dedacbfb31ebc86ccd7af1fbb9491dfd2ed9380c0709767aaacb59240db301 d1be14cc01ad71fc323c95fafbb402c31eb1e5fd36e4524ab05e98e2a54b57fd b4bdc24cc71d97252cf99c645abebb2a6549ec33d51170fb6ea1d90ef0dabc14 971832b5ffb0bcc11a0cb5dd8ce52f7bcd36d8a324e8729eb2b54f18b871e6e6 62ff755f5d90d64563419611710759aabdcf78c5f96bbf6adf421bbef5ad1ee9 Time elapsed in generating 2048-bit prime = (43.363) seconds --------------------------------------------------------------------------- Phi 8ff3b20165fb55d47104e67e6a6473856c0c772751e785cb4158d8163badf689 a12eb97d42fa02125d4ceff4bcfbd94a6ab1644d2b3fc3e9b165116840d0ad23 608006de3d5056084088836d8179f71ad5a684183d3dc8bead36ba426e9ec5f9 0f9b6ca4d5644ac8cce5941954dcbebf544188fa44b82f7a56d5a7fbec06043e 118567dee0d9e503289f6b6e627c900c2eb3a804929645581e1a7670f05ba83c 3eb90c3a51ccce35dcc28d14e0c0558cac2690d6b5514d6e310047990a12d3c0 c75a4bfaa949f53f68c10e9207557b5a992cd8ef59a61aa1312fc93c8688129b 19647415afd60bb68d5b50b8146d08a4c8586627ae8d737cef3fe5024204e16a 923dbc18e40632fcf733ff7a828f4d5a94da4c6a6b308c95fc7191f311a8df91 e71cb6612e6dbe74f1b2b98540c706ec3ea9cce99a7be7245eac103e5fc948bb 12db134c3e1416b22880f57b3a4394d8b0616619a46819907af4982b5ff2eb99 764d1073fd70cf0ca296b3ca9bb2f03d6c68e67061d12d361484a51a34d9480b f746fea9fa9e3a2fe9f33a7dd26a3c75a212477811fc544f86fd797e781784ba 167e51105ada5e7d8afb9bf73db79ad2992d163044a47f5daf45d7d74ea881b8 0fc5be8b6fa33318f8e660d26fe4b5a50db7fd350637c8ca433f64b91556b7e0 1924cf6a120a445fd76c385c7e5bfa60ae486faaa7a81e1a232a51f922a0263 Now Encrypting ... ... ... Ciphertext: ½ÄšNµlÈühd,ЈÂYiÛl×´ÙÄÅ€<$Ñ÷·˜A€F ¯¢9á€QS à†Ó¡5§ ­•• †”go%­)dkVhÿx*E4ùŸoL5UÛ¹ dœzö:“läÝpЀ¨[‘Pd¤.O`?i±ƒå?#‡Ï:EÊr Zº}΄y€`8ß›PÎ ™>ð07 ¿6wvä5íÄY§-Ç-ëƒu¨é•-õÖ÷³‘mU]ªëA39€†v1ùPF~gá¡$Gå89|7Sµ8ïÄá€Êƒt€(H@²Œ„_¦h¯NY"‰‡ÕT•ðû÷o(ÜÊ"^,S4)=«$ 8Â-…ä…S- fR÷âÔ•á•–^}ƒÿAÑ-ý7=áƒE?²¡€$°Úqy.HÂE¨¿´õý„ÉšXBô:/= óz‡µ îÕŠ’óÔæ—¼/[ Transposed Ciphered Text: þ Ä €½HùüNlšhµdÈYÐ,iˆÂÙlÛÄ×´Ñ<Å÷€·$¯AF˜¢€9 à€Sá†QÓ Ï5 • ­%”†g­oÿdV)xk*hL4ŸEù5oœÛ Uz¹dÝ:löp“Ðäd¨‘€¤[.P±?Oƒ`åiE#Ï?ʇr:„Z} yºÎ›•8 P`Îß7™ð >056v¿íwÄä-Y-§ëÇ•uƒ¨-é«÷Ö³]‘Uªm€A3ë†v9~1PùgFå¡á8$9G87|ïSĵ€€ƒá(ÊHt¦²„@hŒ_‡N"¯ÕYT‰(ð÷•ÜûÊo)^S"=,«4 $-…8R…- ä÷Sâf–áÔ^€}€ýÿу7A=-ƒ?á¡E€².°q$HÚÂyý¨´E„¿Éõ/Xôš=B :îzµóÕ‡Š ¼óæ’/Ô[—
  • 18. 17 Encryption took (0.016) seconds ---------------------------------------- Now Decrypting ... ... ... Reversed Transposition ½ÄšNµlÈühd,ЈÂYiÛl×´ÙÄÅ€<$Ñ÷·˜A€F ¯¢9á€QS à†Ó¡5§ ­•• †”go%­)dkVhÿx*E4ùŸoL5UÛ¹ dœzö:“läÝpЀ¨[‘Pd¤.O`?i±ƒå?#‡Ï:EÊr Zº}΄y€`8ß›PÎ ™>ð07 ¿6wvä5íÄY§-Ç-ëƒu¨é•-õÖ÷³‘mU]ªëA39€†v1ùPF~gá¡$Gå89|7Sµ8ïÄá•Êƒt€(H@²Œ„_¦h¯NY"‰‡ÕT•ðû÷o(ÜÊ"^,S4)=«$ 8Â-…ä…S- fR÷âÔ•á•–^}ƒÿAÑ-ý7=áƒE?²¡€$°Úqy.HÂE¨¿´õý„ÉšXBô:/= óz‡µ îÕŠ’óÔæ—¼/[ Decrypted Text: Allah O Akbar Decryption took (0.063) seconds --------------------------------------- Process finished with exit code 0 15. Screenshot Following is the screenshot of the output: 16. Advantages Following are some of the advantages of the proposed enhancement:  Increased difficulty level towards deriving the prime factors of “n”  Key-dependent transposition of ciphered text will entail enemy efforts towards cracking it 17. Future Work Following are suggested as future work:
  • 19. 18  Evolution and implementation of an indigenous Random Number Generator (RNG), preferably Hardware Based.  Key-dependent Generation of the Transposition Key with varied length >= 8 Reference Following are some of the references used: https://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent-of- 65537 https://www.gronau-it-cloud-computing.de/en/cryptographic-key-length-recommendation- from-organizations/