소스 검색

add word_generater_py3.py

duh@133.cn 5 년 전
부모
커밋
80abc50759
1개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 32 0
      pyproject/SSHManager/local_generater/word_generater_py3.py

+ 32 - 0
pyproject/SSHManager/local_generater/word_generater_py3.py

@@ -0,0 +1,32 @@
+# conding: utf-8
+import string
+import base64
+import random
+import sys
+
+def encodestr(s):
+    salt1 = ''.join(random.sample(string.ascii_letters + string.digits, 5))
+    salt2 = ''.join(random.sample(string.ascii_letters + string.digits, 8))
+    ens = ''
+    sens = str(base64.b64encode(s.encode('utf-8')), 'utf-8').strip()
+    sens = sens.strip('=')
+    for num, word in enumerate(sens):
+        if num == 0:
+            ens += salt1
+        if num == len(sens) - 4 and len(sens) > 10:
+            ens += salt2
+        ens += word
+    return ens
+
+
+def decodestr(s):
+    dns = s[5:].replace(s[-12:-4],'') + '=='
+    return str(base64.b64decode(dns.encode('utf-8')),'utf-8')
+
+if __name__ == "__main__":
+    if len(sys.argv) != 3:
+        print("usage: word_generater.py [decodestr]/[encodestr] [string]")
+    if sys.argv[1] == "decode" :
+        print(decodestr(sys.argv[2]))
+    if sys.argv[1] == "encode" :
+        print(encodestr(sys.argv[2]))