SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
import random
from random import randrange, getrandbits
from math import log10
from time import time
from functools import reduce
from itertools import repeat
# FRSA
# By: KHAN FARHAN RAFAT
# This code is provided as it is. No implicit and explicit obligations
# Use @ your own RISK
# Credits: Author
# The RSA result (output) is transposed using a key that can be made dynamic :)
# Contacts: 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
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)
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 = ''
length = len(matrix)
blanks = ''.join(' ' for i in range(length - 1))
for x in range(0, len(words), length):
# todo optimization
item = words[x: x + length] + 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()
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)

Mais conteúdo relacionado

Mais procurados

Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFTimur Safin
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPaulo Sergio Lemes Queiroz
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust languageGines Espada
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat SheetKarlijn Willems
 
The simplest existential graph system
The simplest existential graph systemThe simplest existential graph system
The simplest existential graph systemArmahedi Mahzar
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
20170714 concurrency in julia
20170714 concurrency in julia20170714 concurrency in julia
20170714 concurrency in julia岳華 杜
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revivalNaoki Kitora
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
ゼロから始めるScala文法
ゼロから始めるScala文法ゼロから始めるScala文法
ゼロから始めるScala文法Ryuichi ITO
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesSubhajit Sahu
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat SheetGlowTouch
 

Mais procurados (20)

Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat Sheet
 
Cquestions
Cquestions Cquestions
Cquestions
 
The simplest existential graph system
The simplest existential graph systemThe simplest existential graph system
The simplest existential graph system
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
Py3k
Py3kPy3k
Py3k
 
20170714 concurrency in julia
20170714 concurrency in julia20170714 concurrency in julia
20170714 concurrency in julia
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revival
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
Coding
CodingCoding
Coding
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
2 a networkflow
2 a networkflow2 a networkflow
2 a networkflow
 
ゼロから始めるScala文法
ゼロから始めるScala文法ゼロから始めるScala文法
ゼロから始めるScala文法
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 

Semelhante a Frsa

Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for SpeedYung-Yu Chen
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014PyData
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codePVS-Studio LLC
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」Ken'ichi Matsui
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
Python basic
Python basic Python basic
Python basic sewoo lee
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFTvikram mahendra
 

Semelhante a Frsa (20)

Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Array
ArrayArray
Array
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Python basic
Python basic Python basic
Python basic
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFT
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 

Último

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Último (20)

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

Frsa

  • 1. import random from random import randrange, getrandbits from math import log10 from time import time from functools import reduce from itertools import repeat # FRSA # By: KHAN FARHAN RAFAT # This code is provided as it is. No implicit and explicit obligations # Use @ your own RISK # Credits: Author # The RSA result (output) is transposed using a key that can be made dynamic :) # Contacts: 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
  • 2. 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 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)):
  • 3. 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")
  • 4. 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) aux1 = t2i(ptext[:nbytes]) assert aux1 < mod aux2 = pow(aux1, pk, mod) output += i2l(aux2, size + 2)
  • 5. 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 = '' length = len(matrix) blanks = ''.join(' ' for i in range(length - 1)) for x in range(0, len(words), length): # todo optimization item = words[x: x + length] + blanks
  • 6. 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="")
  • 7. print() 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)
  • 8. 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)
  • 9. 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)