summaryrefslogtreecommitdiff
path: root/day1/task5
diff options
context:
space:
mode:
authorАндрей Гущин <saintruler@gmail.com>2019-03-15 19:32:55 +0300
committerАндрей Гущин <saintruler@gmail.com>2019-03-15 19:32:55 +0300
commit963fab279d069a57ba14e8d77677840272e8c071 (patch)
treed1b5599abb4e048b5f98b1de17ae2eb643c9a26c /day1/task5
parent8916d790f44b95a60fd7ee3001c9e97b703f7ae0 (diff)
parent92b7d6c7b75aa4a6d6a2edc12f76cb45a4d06528 (diff)
Merge branch 'master' into 'day1_task1'
# Conflicts: # .gitignore
Diffstat (limited to 'day1/task5')
-rw-r--r--day1/task5/task5.py20
-rw-r--r--day1/task5/task5_data.txt1
2 files changed, 21 insertions, 0 deletions
diff --git a/day1/task5/task5.py b/day1/task5/task5.py
new file mode 100644
index 0000000..2869247
--- /dev/null
+++ b/day1/task5/task5.py
@@ -0,0 +1,20 @@
+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
new file mode 100644
index 0000000..2dfc0ba
--- /dev/null
+++ b/day1/task5/task5_data.txt
@@ -0,0 +1 @@
+12йцas \ No newline at end of file