Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch. 45 checksum.py - changes output format to columns; fixes the readme #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions file-integrity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ prompt> ./checksum.py -s 1

OPTIONS seed 1
OPTIONS data_size 4
OPTIONS data
OPTIONS data

Decimal: Hex: Bin:
34 0x22 0b00100010
216 0xd8 0b11011000
195 0xc3 0b11000011
65 0x41 0b01000001

Decimal: 34 216 195 65
Hex: 0x22 0xd8 0xc3 0x41
Bin: 0b00100010 0b11011000 0b11000011 0b01000001

Add: ?
Xor: ?
Expand All @@ -61,21 +64,39 @@ prompt>
You can specify a different length for the random data:

```sh
prompt> ./checksum.py -D 2
prompt> ./checksum.py -d 2

OPTIONS seed 0
OPTIONS data_size 2
OPTIONS data

...
Decimal: Hex: Bin:
216 0xd8 0b11011000
194 0xc2 0b11000010


Add: ?
Xor: ?
Fletcher: ?

prompt>
```

You can also specify your own data string:

```sh
prompt> ./checksum.py -D 1,2,3,4

OPTIONS seed 0
OPTIONS data_size 4
OPTIONS data 1,2,3,4

Decimal: 1 2 3 4
Hex: 0x01 0x02 0x03 0x04
Bin: 0b00000001 0b00000010 0b00000011 0b00000100
Decimal: Hex: Bin:
1 0x01 0b00000001
2 0x02 0b00000010
3 0x03 0b00000011
4 0x04 0b00000100


Add: ?
Xor: ?
Expand All @@ -93,9 +114,12 @@ OPTIONS seed 0
OPTIONS data_size 4
OPTIONS data 1,2,3,4

Decimal: 1 2 3 4
Hex: 0x01 0x02 0x03 0x04
Bin: 0b00000001 0b00000010 0b00000011 0b00000100
Decimal: Hex: Bin:
1 0x01 0b00000001
2 0x02 0b00000010
3 0x03 0b00000011
4 0x04 0b00000100


Add: 10 (0b00001010)
Xor: 4 (0b00000100)
Expand Down
27 changes: 13 additions & 14 deletions file-integrity/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ def print_bin(word):

print('')
print('OPTIONS seed', options.seed)
print('OPTIONS data_size', options.data_size)
print('OPTIONS data', options.data)
print('')

random_seed(options.seed)

values = []
if options.data != '':
tmp = options.data.split(',')
for t in tmp:
values.append(int(t))
options.data_size=len(values)
else:
for t in range(int(options.data_size)):
values.append(int(random.random() * 256))

print('OPTIONS data_size', options.data_size)
print('OPTIONS data', options.data)
print('')


add = 0
xor = 0
Expand All @@ -61,20 +62,18 @@ def print_bin(word):
fletcher_a = (fletcher_a + value) % 255
fletcher_b = (fletcher_b + fletcher_a) % 255

print('Decimal: ', end=' ')
for word in values:
print('%10s' % str(word), end=' ')
print('')
# --------------------------------------------

print('Hex: ', end=' ')
print(' Decimal: ', end=' ')
print('Hex: ', end=' ')
print('Bin: ', end='\n')
for word in values:
print(' ', print_hex(word), end=' ')
print('%10s' % str(word), end=' ')
print(' ', print_hex(word), end=' ')
print(' ', print_bin(word), end='\n')
print('')

print('Bin: ', end=' ')
for word in values:
print(print_bin(word), end=' ')
print('')
# --------------------------------------------

print('')
if options.solve:
Expand Down