Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit c30c4b1

Browse files
committed
Added Padded_Parser & Right_Rotator
1 parent a815e28 commit c30c4b1

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from Input_Padder import InputPadder
2+
from Padded_Parser import InputParser
23

34
input_string = str(input("Enter the data: "))
45

56
padded_input_string = InputPadder(input_string).pad_input()
67

7-
print("Padded Input String: ", padded_input_string)
8+
print("Padded Input String: ", padded_input_string)
9+
10+
expanded_message_schedule = InputParser(padded_input_string).process_chunks()
11+
12+
print("Expanded Message Schedule: ", expanded_message_schedule)

Padded_Parser.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import struct
2+
from Right_Rotator import RightRotator
3+
4+
class InputParser:
5+
def __init__(self, input_data):
6+
self.input_data = input_data
7+
8+
def process_chunks(self):
9+
result = []
10+
for i in range(0, len(self.input_data), 64):
11+
chunk = self.input_data[i:i + 64]
12+
w = list(struct.unpack('>16L', chunk)) + [0] * 48
13+
for i in range(16, 64):
14+
s0 = RightRotator(w[i - 15], 7).right_rotate() ^ RightRotator(w[i - 15], 18).right_rotate() ^ (w[i - 15] >> 3)
15+
s1 = RightRotator(w[i - 2], 17).right_rotate() ^ RightRotator(w[i - 2], 19).right_rotate() ^ (w[i - 2] >> 10)
16+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) & 0xFFFFFFFF
17+
18+
result.append(w)
19+
20+
return result

Right_Rotator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class RightRotator:
2+
def __init__(self, value, bits):
3+
self.value = value
4+
self.bits = bits
5+
6+
def right_rotate(self):
7+
return ((self.value >> self.bits) | (self.value << (32 - self.bits))) & 0xFFFFFFFF

0 commit comments

Comments
 (0)