瀏覽代碼

add function to replace one letter with a special
sign, random_special, sign

oz123 12 年之前
父節點
當前提交
17248a053f
共有 1 個文件被更改,包括 32 次插入0 次删除
  1. 32 0
      pwman/util/generator.py

+ 32 - 0
pwman/util/generator.py

@@ -66,6 +66,38 @@ def leetify(password):
         newpassword = newpassword + l
     return newpassword
 
+def random_special_sign(password):
+    """
+    replace one letter with a special sign,
+    this will do the following:
+    In [203]: for i in range(10):
+    print random_special_sign("secret")
+    .....:     
+    secre%
+    sec\et
+    secre?
+    s;cret
+    se$ret
+    secr}t
+    secr*t
+    ;ecret
+    s%cret
+    secre(
+    """
+    newpass = str()
+    specialsigns = ["@", "#", "?", "!", '\\', "|", "$",
+                     "%", "^", "&", "*", "(", ")", ":", ";",
+                     "{", "}", "+","-"]
+                     
+    place = int(random.randint(0, len(password)-1))
+    randomsign = specialsigns[int(random.randint(0, len(specialsigns)-1))]
+    for idx, letter in enumerate(password):
+        if not idx == place:
+            newpass = newpass + letter
+        if idx == place:
+            newpass = newpass + randomsign
+    return newpass
+    
 def change_numerics(password):
     newpassword = str()
     for l in password: