SlideShare a Scribd company logo
For any help regarding Python Homework Help
visit : - https://www.pythonhomeworkhelp.com/,
Email :- support@pythonhomeworkhelp.com or
call us at :- +1 (315) 557-6473
Problem 1. Kalns
Ben Bitdiddle has designed a new cryptosystem called Kalns, but we suspect it might not be as strong
as we would like to be. Therefore we ask your help to break it.
In this problem we will be working with a finite field GF16. The elements of our field are all 4-bit strings.
The field addition is computed as xor: GF16(x) + GF16(y) = GF16(x ⊕
y). We provide the two tables describing addition and multiplication laws on the course web page.
If you are curious, these tables are obtained by interpreting 4-bit field elements as degree≤
4 polynomials over GF2 and performing addition and multiplication modulo the irreducible polynomial
x4 + x + 1.
However, for the purposes of this problem you do not need to understand how our GF16 is constructed;
the solutions we know assume black-box access to GF16. We have provided a GF16 implementation for
you.
Kalns is a 64-bit block cipher. The secret key consists of three parts:
•an invertible 16-by-16 matrix A over GF16;
•a 16-element vector b over GF16; and
•a permutation (bijection) S that maps GF16 one-to-one and onto GF16.
https://www.pythonhomeworkhelp.com/
To encrypt a 64-bit block B we first break it up in sixteen 4-bit chunks and interpret each of them as a
GF16 element. So block B corresponds to length 16 vector x = (x0, . . . , x15) over GF16.
The encryptions consists of the following: y = S(Ax + b), where the permutation S is individually applied
to each of 16 elements of v = Ax + b. The 16-element vector y is later re-interpreted as 64-bit integer to
obtain the encrypted block B'.
(a) Ben suspects that his cryptosystem is very secure. After all it has around 16162 1616 16! 21132.25
possible keys. However, we suspect that there are many equivalent keys. These keys have different
values for (A, b, S), but produce the same ciphertext for any given plaintext. Is our suspicion well-
founded?
(b) Describe a chosen-ciphertext attack on Kalns that recovers the unknown key (A, b, S) or an
equivalent key.
https://www.pythonhomeworkhelp.com/
Solution:
class GF16(object):
"""Implementation of GF(2^4) as degree 4 polynomials over GF(2) modulo
x^4 + x + 1.
"""
def __init__(self, val):
if not (isinstance(val, int) or isinstance(val, long)) or val < 0 or val > 15:
raise ValueError("GF16 elements must be constructed from integers from 0 to 15.")
self.val = val
def __repr__(self):
return "GF16(%d)" % self.val
def __add__(self, other):
if not isinstance(other, GF16):
raise ValueError("Addition is only defined between a GF16 element and GF16 element")
return GF16(self.val ^ other.val)
def __sub__(self, other):
if not isinstance(other, GF16):
raise ValueError("Subtraction is only defined between a GF16 element and GF16 element")
# +1 equals -1 (mod 2), so both operations are XOR
return GF16(self.val ^ other.val)
https://www.pythonhomeworkhelp.com/
def __neg__(self):
# +1 equals -1 (mod 2), so negation is the same element
return GF16(self.val)
def __mul__(self, other):
if not isinstance(other, GF16):
raise ValueError("Multiplication is only defined between a GF16 element and GF16 element")
a, b = self.val, other.val
r = 0
for c in xrange(4):
if b & 1:
r = r^a
a <<= 1
if a & 16 == 16:
a ^= (16 + 2 + 1) # subtract x^4 + x + 1
b >>= 1
return GF16(r)
def __div__(self, other):
if not isinstance(other, GF16):
raise ValueError("Division is only defined between a GF16 element and GF16 element")
return self * other.inverse()
__truediv__ = __div__
https://www.pythonhomeworkhelp.com/
def __eq__(self, other):
if isinstance(other, GF16):
return self.val == other.val
else:
return False
def __ne__(self, other):
if isinstance(other, GF16):
return self.val != other.val
else:
return True
def inverse(self):
if self.val == 0:
raise ValueError("Zero is not invertible.")
# We know that x^15 = x^14 * x = 1, so x^14 = x^{-1}
s2 = self * self
s4 = s2 * s2
s7 = self * s2 * s4
s14 = s7 * s7
return s14
def test_GF16():
# associativity
https://www.pythonhomeworkhelp.com/
for a in xrange(16):
for b in xrange(16):
for c in xrange(16):
assert GF16(a) * (GF16(b) * GF16(c)) == (GF16(a) * GF16(b)) * GF16(c)
assert GF16(a) + (GF16(b) + GF16(c)) == (GF16(a) + GF16(b)) + GF16(c)
# commutativity
for a in xrange(16):
for b in xrange(16):
assert GF16(a) * GF16(b) == GF16(b) * GF16(a)
assert GF16(a) + GF16(b) == GF16(b) + GF16(a)
# distributivity
for a in xrange(16):
for b in xrange(16):
for c in xrange(16):
assert GF16(a) * (GF16(b) + GF16(c)) == GF16(a) * GF16(b) + GF16(a) * GF16(c)
# inverses
for a in xrange(16):
assert GF16(a) + (-GF16(a)) == GF16(0)
for a in xrange(1, 16):
assert GF16(a) * (GF16(a).inverse()) == GF16(1)
https://www.pythonhomeworkhelp.com/
def matrix_by_vector(A, x):
zero = type(x[0])(0)
result = []
for row in A:
assert len(row) == len(x)
c = sum((rowi * xi for rowi, xi in zip(row, x)), zero)
result.append(c)
return result
def matrix_by_matrix(A, B):
zero = type(A[0][0])(0)
C = []
for i in xrange(len(A)):
Ci = []
for j in xrange(len(A[i])):
Cij = sum((A[i][k] * B[k][j] for k in xrange(len(A[i]))), zero)
Ci.append(Cij)
C.append(Ci)
return C
def matrix_inverse(A):
# O(n^3) inversion using Gauss-Jordan algorithm
https://www.pythonhomeworkhelp.com/
zero = type(A[0][0])(0)
one = type(A[0][0])(1)
n = len(A)
M = [A[i] + [zero] * i + [one] + [zero] * (n-1-i) for i in xrange(n)] # augment with identity matrix
# first make the matrix in upper-triangular form
for i in xrange(n):
pivot = None
for j in xrange(i, n):
if M[j][i] != zero:
pivot = j
break
if pivot is None:
raise ValueError, "Matrix is not invertible?"
# swap rows i and pivot
if pivot != i:
M[pivot], M[i] = M[i], M[pivot]
# divide out the row itself by the diagonal element
multiple = M[i][i]
for k in xrange(2*n):
M[i][k] /= multiple
https://www.pythonhomeworkhelp.com/
# subtract this row appropriate number of times for every row below it
for j in xrange(i+1, n):
multiple = M[j][i]
for k in xrange(2*n):
M[j][k] -= M[i][k] * multiple
# then work our way back up
for i in xrange(n-1, -1, -1):
for j in xrange(i-1, -1, -1):
multiple = M[j][i]
for k in xrange(2*n):
M[j][k] -= M[i][k] * multiple
# return the augmented part
return [M[i][n:] for i in xrange(n)]
def test_matrix_inverse(n):
r = range(n)
random.shuffle(r)
P = [[GF16(0)] * n for i in xrange(n)]
L = [[GF16(0)] * n for i in xrange(n)]
U = [[GF16(0)] * n for i in xrange(n)]
for i in xrange(n):
https://www.pythonhomeworkhelp.com/
P[i][r[i]] = GF16(1)
L[i][i] = GF16(random.randint(1, 15))
U[i][i] = GF16(random.randint(1, 15))
for j in xrange(i):
L[i][j] = GF16(random.randint(0, 15))
for j in xrange(i+1, n):
U[i][j] = GF16(random.randint(0, 15))
M = matrix_by_matrix(matrix_by_matrix(L, U), P)
Minv = matrix_inverse(M)
MMinv = matrix_by_matrix(M, Minv)
for i in xrange(n):
for j in xrange(n):
assert MMinv[i][j] == (GF16(1) if i == j else GF16(0))
def vector_add(u, v):
assert len(u) == len(v)
return [ui + vi for ui, vi in zip(u, v)]
def vector_sub(u, v):
assert len(u) == len(v)
return [ui - vi for ui, vi in zip(u, v)]
def random_GF16_vector(n):
return [GF16(random.randint(0, 15)) for i in xrange(n)]
https://www.pythonhomeworkhelp.com/
def random_GF16_matrix(n):
return [random_GF16_vector(n) for i in xrange(n)]
def random_invertible_GF16_matrix(n):
while True:
M = random_GF16_matrix(n)
try:
Minv = matrix_inverse(M)
except ValueError, e:
continue
return M
def int64_to_GF16_vec(x):
v = [None] * 16
for i in xrange(16):
v[15-i] = GF16(x & 15)
x >>= 4
assert x == 0
return v
def GF16_vec_to_int64(v):
assert len(v) == 16
x = 0
for el in v:
x = (x << 4) | el.val
return x
https://www.pythonhomeworkhelp.com/

More Related Content

Similar to Introduction to Python Programming.pptx

High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
Johan Tibell
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and Decoder
Ameer H Ali
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
Vlad Patryshev
 
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptxAIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
Zawarali786
 
Algorithms Design Homework Help
Algorithms Design Homework HelpAlgorithms Design Homework Help
Algorithms Design Homework Help
Programming Homework Help
 
Minerva_lib - fuzzing tool
Minerva_lib - fuzzing toolMinerva_lib - fuzzing tool
Minerva_lib - fuzzing tool
Logicaltrust pl
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
Programming Exam Help
 
Understanding the "Chain Rule" for Derivatives by Deriving Your Own Version
Understanding the "Chain Rule" for Derivatives by Deriving Your Own VersionUnderstanding the "Chain Rule" for Derivatives by Deriving Your Own Version
Understanding the "Chain Rule" for Derivatives by Deriving Your Own Version
James Smith
 
Algorithms DM
Algorithms DMAlgorithms DM
Algorithms DM
Rokonuzzaman Rony
 
AIOU Code 1349 Solved Assignment 2 Autumn 2022.pptx
AIOU Code 1349 Solved Assignment 2 Autumn 2022.pptxAIOU Code 1349 Solved Assignment 2 Autumn 2022.pptx
AIOU Code 1349 Solved Assignment 2 Autumn 2022.pptx
Zawarali786
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
Eleanor McHugh
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Introduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve CryptographyIntroduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve Cryptography
David Evans
 
Programming Hp33s talk v3
Programming Hp33s talk v3Programming Hp33s talk v3
Programming Hp33s talk v3
Land Surveyors United Community
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
Knoldus Inc.
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
Meetu Maltiar
 
Monadologie
MonadologieMonadologie
Monadologie
league
 
Ecc2
Ecc2Ecc2
11 - Programming languages
11 - Programming languages11 - Programming languages
11 - Programming languages
Tudor Girba
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
Guy Komari
 

Similar to Introduction to Python Programming.pptx (20)

High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and Decoder
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
 
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptxAIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
 
Algorithms Design Homework Help
Algorithms Design Homework HelpAlgorithms Design Homework Help
Algorithms Design Homework Help
 
Minerva_lib - fuzzing tool
Minerva_lib - fuzzing toolMinerva_lib - fuzzing tool
Minerva_lib - fuzzing tool
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
Understanding the "Chain Rule" for Derivatives by Deriving Your Own Version
Understanding the "Chain Rule" for Derivatives by Deriving Your Own VersionUnderstanding the "Chain Rule" for Derivatives by Deriving Your Own Version
Understanding the "Chain Rule" for Derivatives by Deriving Your Own Version
 
Algorithms DM
Algorithms DMAlgorithms DM
Algorithms DM
 
AIOU Code 1349 Solved Assignment 2 Autumn 2022.pptx
AIOU Code 1349 Solved Assignment 2 Autumn 2022.pptxAIOU Code 1349 Solved Assignment 2 Autumn 2022.pptx
AIOU Code 1349 Solved Assignment 2 Autumn 2022.pptx
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Introduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve CryptographyIntroduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve Cryptography
 
Programming Hp33s talk v3
Programming Hp33s talk v3Programming Hp33s talk v3
Programming Hp33s talk v3
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Monadologie
MonadologieMonadologie
Monadologie
 
Ecc2
Ecc2Ecc2
Ecc2
 
11 - Programming languages
11 - Programming languages11 - Programming languages
11 - Programming languages
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 

More from Python Homework Help

Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Complete my Python Homework
Complete my Python HomeworkComplete my Python Homework
Complete my Python Homework
Python Homework Help
 
Introduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptxIntroduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptx
Python Homework Help
 
Basic Python Programming.pptx
Basic Python Programming.pptxBasic Python Programming.pptx
Basic Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptxPython Programming Homework Help.pptx
Python Programming Homework Help.pptx
Python Homework Help
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
Python Homework Help
 
Perfect Python Homework Help
Perfect Python Homework HelpPerfect Python Homework Help
Perfect Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 

More from Python Homework Help (20)

Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Complete my Python Homework
Complete my Python HomeworkComplete my Python Homework
Complete my Python Homework
 
Introduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptxIntroduction to Python Dictionary.pptx
Introduction to Python Dictionary.pptx
 
Basic Python Programming.pptx
Basic Python Programming.pptxBasic Python Programming.pptx
Basic Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Python Programming Homework Help.pptx
Python Programming Homework Help.pptxPython Programming Homework Help.pptx
Python Programming Homework Help.pptx
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
 
Perfect Python Homework Help
Perfect Python Homework HelpPerfect Python Homework Help
Perfect Python Homework Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 

Recently uploaded

What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 

Recently uploaded (20)

What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 

Introduction to Python Programming.pptx

  • 1. For any help regarding Python Homework Help visit : - https://www.pythonhomeworkhelp.com/, Email :- support@pythonhomeworkhelp.com or call us at :- +1 (315) 557-6473
  • 2. Problem 1. Kalns Ben Bitdiddle has designed a new cryptosystem called Kalns, but we suspect it might not be as strong as we would like to be. Therefore we ask your help to break it. In this problem we will be working with a finite field GF16. The elements of our field are all 4-bit strings. The field addition is computed as xor: GF16(x) + GF16(y) = GF16(x ⊕ y). We provide the two tables describing addition and multiplication laws on the course web page. If you are curious, these tables are obtained by interpreting 4-bit field elements as degree≤ 4 polynomials over GF2 and performing addition and multiplication modulo the irreducible polynomial x4 + x + 1. However, for the purposes of this problem you do not need to understand how our GF16 is constructed; the solutions we know assume black-box access to GF16. We have provided a GF16 implementation for you. Kalns is a 64-bit block cipher. The secret key consists of three parts: •an invertible 16-by-16 matrix A over GF16; •a 16-element vector b over GF16; and •a permutation (bijection) S that maps GF16 one-to-one and onto GF16. https://www.pythonhomeworkhelp.com/
  • 3. To encrypt a 64-bit block B we first break it up in sixteen 4-bit chunks and interpret each of them as a GF16 element. So block B corresponds to length 16 vector x = (x0, . . . , x15) over GF16. The encryptions consists of the following: y = S(Ax + b), where the permutation S is individually applied to each of 16 elements of v = Ax + b. The 16-element vector y is later re-interpreted as 64-bit integer to obtain the encrypted block B'. (a) Ben suspects that his cryptosystem is very secure. After all it has around 16162 1616 16! 21132.25 possible keys. However, we suspect that there are many equivalent keys. These keys have different values for (A, b, S), but produce the same ciphertext for any given plaintext. Is our suspicion well- founded? (b) Describe a chosen-ciphertext attack on Kalns that recovers the unknown key (A, b, S) or an equivalent key. https://www.pythonhomeworkhelp.com/
  • 4. Solution: class GF16(object): """Implementation of GF(2^4) as degree 4 polynomials over GF(2) modulo x^4 + x + 1. """ def __init__(self, val): if not (isinstance(val, int) or isinstance(val, long)) or val < 0 or val > 15: raise ValueError("GF16 elements must be constructed from integers from 0 to 15.") self.val = val def __repr__(self): return "GF16(%d)" % self.val def __add__(self, other): if not isinstance(other, GF16): raise ValueError("Addition is only defined between a GF16 element and GF16 element") return GF16(self.val ^ other.val) def __sub__(self, other): if not isinstance(other, GF16): raise ValueError("Subtraction is only defined between a GF16 element and GF16 element") # +1 equals -1 (mod 2), so both operations are XOR return GF16(self.val ^ other.val) https://www.pythonhomeworkhelp.com/
  • 5. def __neg__(self): # +1 equals -1 (mod 2), so negation is the same element return GF16(self.val) def __mul__(self, other): if not isinstance(other, GF16): raise ValueError("Multiplication is only defined between a GF16 element and GF16 element") a, b = self.val, other.val r = 0 for c in xrange(4): if b & 1: r = r^a a <<= 1 if a & 16 == 16: a ^= (16 + 2 + 1) # subtract x^4 + x + 1 b >>= 1 return GF16(r) def __div__(self, other): if not isinstance(other, GF16): raise ValueError("Division is only defined between a GF16 element and GF16 element") return self * other.inverse() __truediv__ = __div__ https://www.pythonhomeworkhelp.com/
  • 6. def __eq__(self, other): if isinstance(other, GF16): return self.val == other.val else: return False def __ne__(self, other): if isinstance(other, GF16): return self.val != other.val else: return True def inverse(self): if self.val == 0: raise ValueError("Zero is not invertible.") # We know that x^15 = x^14 * x = 1, so x^14 = x^{-1} s2 = self * self s4 = s2 * s2 s7 = self * s2 * s4 s14 = s7 * s7 return s14 def test_GF16(): # associativity https://www.pythonhomeworkhelp.com/
  • 7. for a in xrange(16): for b in xrange(16): for c in xrange(16): assert GF16(a) * (GF16(b) * GF16(c)) == (GF16(a) * GF16(b)) * GF16(c) assert GF16(a) + (GF16(b) + GF16(c)) == (GF16(a) + GF16(b)) + GF16(c) # commutativity for a in xrange(16): for b in xrange(16): assert GF16(a) * GF16(b) == GF16(b) * GF16(a) assert GF16(a) + GF16(b) == GF16(b) + GF16(a) # distributivity for a in xrange(16): for b in xrange(16): for c in xrange(16): assert GF16(a) * (GF16(b) + GF16(c)) == GF16(a) * GF16(b) + GF16(a) * GF16(c) # inverses for a in xrange(16): assert GF16(a) + (-GF16(a)) == GF16(0) for a in xrange(1, 16): assert GF16(a) * (GF16(a).inverse()) == GF16(1) https://www.pythonhomeworkhelp.com/
  • 8. def matrix_by_vector(A, x): zero = type(x[0])(0) result = [] for row in A: assert len(row) == len(x) c = sum((rowi * xi for rowi, xi in zip(row, x)), zero) result.append(c) return result def matrix_by_matrix(A, B): zero = type(A[0][0])(0) C = [] for i in xrange(len(A)): Ci = [] for j in xrange(len(A[i])): Cij = sum((A[i][k] * B[k][j] for k in xrange(len(A[i]))), zero) Ci.append(Cij) C.append(Ci) return C def matrix_inverse(A): # O(n^3) inversion using Gauss-Jordan algorithm https://www.pythonhomeworkhelp.com/
  • 9. zero = type(A[0][0])(0) one = type(A[0][0])(1) n = len(A) M = [A[i] + [zero] * i + [one] + [zero] * (n-1-i) for i in xrange(n)] # augment with identity matrix # first make the matrix in upper-triangular form for i in xrange(n): pivot = None for j in xrange(i, n): if M[j][i] != zero: pivot = j break if pivot is None: raise ValueError, "Matrix is not invertible?" # swap rows i and pivot if pivot != i: M[pivot], M[i] = M[i], M[pivot] # divide out the row itself by the diagonal element multiple = M[i][i] for k in xrange(2*n): M[i][k] /= multiple https://www.pythonhomeworkhelp.com/
  • 10. # subtract this row appropriate number of times for every row below it for j in xrange(i+1, n): multiple = M[j][i] for k in xrange(2*n): M[j][k] -= M[i][k] * multiple # then work our way back up for i in xrange(n-1, -1, -1): for j in xrange(i-1, -1, -1): multiple = M[j][i] for k in xrange(2*n): M[j][k] -= M[i][k] * multiple # return the augmented part return [M[i][n:] for i in xrange(n)] def test_matrix_inverse(n): r = range(n) random.shuffle(r) P = [[GF16(0)] * n for i in xrange(n)] L = [[GF16(0)] * n for i in xrange(n)] U = [[GF16(0)] * n for i in xrange(n)] for i in xrange(n): https://www.pythonhomeworkhelp.com/
  • 11. P[i][r[i]] = GF16(1) L[i][i] = GF16(random.randint(1, 15)) U[i][i] = GF16(random.randint(1, 15)) for j in xrange(i): L[i][j] = GF16(random.randint(0, 15)) for j in xrange(i+1, n): U[i][j] = GF16(random.randint(0, 15)) M = matrix_by_matrix(matrix_by_matrix(L, U), P) Minv = matrix_inverse(M) MMinv = matrix_by_matrix(M, Minv) for i in xrange(n): for j in xrange(n): assert MMinv[i][j] == (GF16(1) if i == j else GF16(0)) def vector_add(u, v): assert len(u) == len(v) return [ui + vi for ui, vi in zip(u, v)] def vector_sub(u, v): assert len(u) == len(v) return [ui - vi for ui, vi in zip(u, v)] def random_GF16_vector(n): return [GF16(random.randint(0, 15)) for i in xrange(n)] https://www.pythonhomeworkhelp.com/
  • 12. def random_GF16_matrix(n): return [random_GF16_vector(n) for i in xrange(n)] def random_invertible_GF16_matrix(n): while True: M = random_GF16_matrix(n) try: Minv = matrix_inverse(M) except ValueError, e: continue return M def int64_to_GF16_vec(x): v = [None] * 16 for i in xrange(16): v[15-i] = GF16(x & 15) x >>= 4 assert x == 0 return v def GF16_vec_to_int64(v): assert len(v) == 16 x = 0 for el in v: x = (x << 4) | el.val return x https://www.pythonhomeworkhelp.com/