-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06-base64.py
96 lines (71 loc) · 5.65 KB
/
06-base64.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import base64
from urllib import parse
name = 'myoungseok' # 1. 문자열
name_bytes = name .encode('ascii') # 2. bytes형 변환
name_base64 = base64.b64encode(name_bytes) #3. base64인코딩
name_base64_str = name_base64.decode('ascii') # 결과값 문자열로 만들기
print(name)
print(name_bytes)
print(name_base64)
print(name_base64_str)
# 문제 풀이
# 1. guest를 문제에 따라서 20번 인코딩 후, 문자열 치환
result ='''Vm0wd%40QyUXlVWGxWV0d%5EV%21YwZDRWMVl%24WkRSV0%21WbDNXa%21JTVjAxV%40JETlhhMUpUVmpBeFYySkVUbGhoTVVwVVZtcEJlRll%26U%40tWVWJHaG9UVlZ%24VlZadGNFSmxSbGw%21VTJ0V%21ZXSkhhRzlVVmxaM%21ZsWmFjVkZ0UmxSTmJFcEpWbTEwYTFkSFNrZGpSVGxhVmpOU%21IxcFZXbUZrUjA%21R%21UyMTRVMkpIZHpGV%21ZFb%24dWakZhV0ZOcmFHaFNlbXhXVm%21wT%21QwMHhjRlpYYlVaclVqQTFSMXBGV%40xOVWJGcFlaSHBHVjFaRmIzZFdha%21poVjBaT%40NtRkhhRk%26sYlhoWFZtMHhORmxWTUhoWGJrNVlZbFZhY%40xWcVFURlNNVlY%21VFZSU%21ZrMXJjRWxhU0hCSFZqRmFSbUl%2AWkZkaGExcG9WakJhVDJOdFJraGhSazVzWWxob%21dGWnRNWGRVTVZGM%21RVaG9hbEpzY0ZsWmJGWmhZMnhXY%21ZGVVJsTk%26WbFkxVkZaU%21UxWnJNWEpqUld%5E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ZHV%40xwaVdHaG9WbTE0YzJOc%21pISmtSM0JUWWtad0%26GWlhNVEJOUmxsNFYyNU9hbEpYYUZoV%40FrNVRWRVpzVlZGWWFGTldhM0I%40VmtkNFlWVXlTa%21pYV0hCWFZsWndSMVF%5EV%40tOVmJFSlZUVVF%24UFE9PQ%3D%3D'''
string = 'guest'
string_bytes = string.encode('ascii')
string_base64 = string_bytes
for i in range(20):
string_base64 = base64.b64encode(string_base64)
string_base64_20_str = string_base64.decode('ascii')
replace_str = string_base64_20_str
replace_str = replace_str.replace("1","!")
replace_str = replace_str.replace("2","@")
replace_str = replace_str.replace("3","$")
replace_str = replace_str.replace("4","^")
replace_str = replace_str.replace("5","&")
replace_str = replace_str.replace("6","*")
replace_str = replace_str.replace("7","(")
replace_str = replace_str.replace("8",")")
replace_str_url_encode = parse.quote(replace_str)
if(replace_str_url_encode == result):
print("쿠키 값과 내가 인코딩 한 값이 동일")
else:
print("쿠키 값과 내가 인코딩 한 값이 다름")
# 디코딩
# 위에서 인코딩한 내용을 디코딩 한다.
## 치환 -> 디코딩
## 디코딩 해야 할 문자열 : replace_str
### 치환
replace_str = replace_str.replace("!","1")
replace_str = replace_str.replace("@","2")
replace_str = replace_str.replace("$","3")
replace_str = replace_str.replace("^","4")
replace_str = replace_str.replace("&","5")
replace_str = replace_str.replace("*","6")
replace_str = replace_str.replace("(","7")
replace_str = replace_str.replace(")","8")
replace_str_bytes = replace_str.encode("ascii")
### base64 디코딩 20번
replace_str_64decoded = replace_str_bytes
for i in range(20):
replace_str_64decoded = base64.b64decode(replace_str_64decoded)
decoded_str = replace_str_64decoded.decode("ascii")
def base64_encode_20(string):
string_bytes = string.encode('ascii')
string_base64 = string_bytes
for i in range(20):
string_base64 = base64.b64encode(string_base64)
#print(string_base64)
string_base64_20_str = string_base64.decode('ascii')
replace_str = string_base64_20_str
replace_str = replace_str.replace("1","!")
replace_str = replace_str.replace("2","@")
replace_str = replace_str.replace("3","$")
replace_str = replace_str.replace("4","^")
replace_str = replace_str.replace("5","&")
replace_str = replace_str.replace("6","*")
replace_str = replace_str.replace("7","(")
replace_str = replace_str.replace("8",")")
return replace_str
base64_encode_20("admin")
base64_encode_20("nimda")