summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rw-r--r--day1/task5/task5.py33
-rw-r--r--day1/task5/task5_data.txt2
2 files changed, 20 insertions, 15 deletions
diff --git a/day1/task5/task5.py b/day1/task5/task5.py
index 52eafc2..2869247 100644
--- a/day1/task5/task5.py
+++ b/day1/task5/task5.py
@@ -1,15 +1,20 @@
-with open('task5_data.txt') as f:
- print(f.read())
-
-with open('task5_data.txt', 'rb+') as input_byte, open('task5_data_new.txt', 'wb') as out:
- char = input_byte.read(1)
- while char:
- binary = list(bin(int(char.hex(), 16))[2:])
- if binary[-2] == '1':
- binary[-2] = '0'
- elif binary[-2] == '0':
- binary[-2] = '1'
-
- out.write(bytes([int(''.join(binary), 2)]))
- char = input_byte.read(1)
+import os
+
+read_path = os.path.join(os.getcwd(), 'task5_data.txt')
+write_path = os.path.join(os.getcwd(), 'task5_data_new.txt')
+
+if not os.access(read_path, os.R_OK):
+ print('Файл "{}" не доступен для чтения'.format(read_path))
+elif not os.access(write_path, os.W_OK):
+ print('Файл "{}" не доступен для записи'.format(write_path))
+else:
+ with open(read_path) as f:
+ print(f.read())
+
+ with open('task5_data.txt', 'rb') as input_byte, open(write_path, 'wb') as out:
+ char = input_byte.read(1)
+ while char:
+ number = int(char.hex(), 16)
+ out.write(bytes([number ^ 2]))
+ char = input_byte.read(1)
diff --git a/day1/task5/task5_data.txt b/day1/task5/task5_data.txt
index 0808eaa..2dfc0ba 100644
--- a/day1/task5/task5_data.txt
+++ b/day1/task5/task5_data.txt
@@ -1 +1 @@
-12йцas
+12йцas \ No newline at end of file