A1_sol
A1_sol
You can use the following online tool for this question: https://crypto.interactive-
maths.com/columnar-transposition-cipher.html
Solution 1.1
If we use the key: zmuxv, we get the following ciphertext:
LHELRECADESESOOACOOSELLRETANKNNYIDTZDOUATCIHGVANIEFCRCSBCTOPDEREGRRNI
"GTGYIGSIVANTIGRMFNONAHESONIIONRLBNIVTWLLMETRELIVLNNELGISEYEAENDEATRLNETEFIURNEIELSAL"
Solution 1.2
By using the given key, the given ciphertext decrypts to:
thegreatestgloryinlivingliesnotinneverfallingbutinrisingeverytimewefallnelsonmandela
1
”The greatest glory in living lies not in never falling but in rising every time we
fall.” -Nelson Mandela
You can use the following online tool for this question: https://www.101computing.net/mono-
alphabetic-substitution-cipher/
Solution 2
Using the following key:
zyxwvutsrqponmlkjihgfedcba
E(x) = (a · x + b) mod 26
where a and b are the keys and x is the numeric equivalent of a letter in the
alphabet.
2
You can use the following online tool for this question: https://cryptii.com/pipes/affine-
cipher
Solution 3.1
The encrypted message is: ZFRNSFADZA
E(x) = (a · x + b) mod 26
where:
• a=7
• b=3
• x is the numeric position of a letter in the alphabet (A = 0, B = 1, C =
2, . . . , Z = 25).
Let’s encrypt the message "SECUREHASH".
E(x) = (7 · x + 3) mod 26
• S = (7 · 18 + 3) mod 26 = (126 + 3) mod 26 = 129 mod 26 =
25 (Z)
• E = (7 · 4 + 3) mod 26 = (28 + 3) mod 26 = 31 mod 26 = 5 (F )
• C = (7 · 2 + 3) mod 26 = (14 + 3) mod 26 = 17 mod 26 = 17 (R)
• U = (7 · 20 + 3) mod 26 = (140 + 3) mod 26 = 143 mod 26 =
13 (N )
• R = (7 · 17 + 3) mod 26 = (119 + 3) mod 26 = 122 mod 26 =
18 (S)
• E = (7 · 4 + 3) mod 26 = (28 + 3) mod 26 = 31 mod 26 = 5 (F )
• H = (7 · 7 + 3) mod 26 = (49 + 3) mod 26 = 52 mod 26 = 0 (A)
• A = (7 · 0 + 3) mod 26 = (0 + 3) mod 26 = 3 mod 26 = 3 (D)
3
• S = (7 · 18 + 3) mod 26 = (126 + 3) mod 26 = 129 mod 26 =
25 (Z)
• H = (7 · 7 + 3) mod 26 = (49 + 3) mod 26 = 52 mod 26 = 0 (A)
3. Convert back to letters:
"ZFRNSFADZA"
Solution 3.2
The decrypted message is: HELLOHOWAREYOU
7 · a−1 ≡ 1 mod 26
The modular inverse of 7 modulo 26 is 15 because:
7 · 15 = 105 ≡ 1 mod 26
Thus, a−1 = 15.
4
Step 3: Convert the ciphertext into numeric val-
ues
Let’s convert each letter of the ciphertext "AFCCXAXBDSFPXN" into its corre-
sponding numeric value:
• A=0
• F=5
• C=2
• C=2
• X = 23
• A=0
• X = 23
• B=1
• D=3
• S = 18
• F=5
• P = 15
• X = 23
• N = 13
D(y) = 15 · (y − 3) mod 26
Let’s apply the formula to each value:
1. A = 0:
5
2. F = 5:
5. X = 23:
10. S = 18:
6
11. F = 5 (again):
14. N = 13:
HELLOHOWAREYOU
Solution 3.3
7
Algorithm 1 AffineEncrypt(plaintext, a, b)
Input: plaintext, a, b
Output: encrypted text
8
Algorithm 2 AffineDecrypt(ciphertext, a, b)
Input: ciphertext, a, b
Output: decrypted text
9
Problem 4: Cryptographic Hash Functions and
Collisions (20 points)
Hash functions play a critical role in blockchain technology. Consider the fol-
lowing hash function:
Solution 4.1
This function is not collision-resistant. Example:
For x1 = 12 and x2 = 17, we get the same hash value: H(12) = H(17) = 7.
Solution 4.2
Collision resistance prevents double-spending attacks by ensuring that two dif-
ferent transactions cannot produce the same hash.
Solution 5.1:
1 require(isPaid == false, "Rent has already been paid this month
.");
10
Problem 5.2 (4 points)
Fill in the missing condition in payRent() to check if the payment is late. Use
the dueDate to determine if the tenant has missed the due date.
Solution 5.2:
1 if (block.timestamp > dueDate) {
2 // Apply penalty
3 rentAmount += penaltyAmount;
4 }
Solution 5.3:
1 require(block.timestamp > dueDate, "Cannot reset payment status
until the new month starts.");
Solution 5.4: One logical flaw is that when the tenant pays late, the penalty
is added to the rentAmount directly. This causes an issue because the increased
rentAmount (including the penalty) remains in effect for future months if it is
not reset after payment. This means future rent payments could incorrectly
include the penalty.
To fix this: After the payment is made, the rentAmount should be reset to
its original value (without the penalty) so that subsequent payments are not
affected by previous penalties.
Here’s how we can fix it in the payRent() function:
1 // Transfer rent to landlord
2 landlord.transfer(rentAmount);
3 isPaid = true;
4
This ensures that the penalty is applied only for the late payment and does
not persist into the next month.
11