Commit bc596d4e by tarokkk

laborclient: Fixed enc.py

parent a8d35c33
...@@ -13,6 +13,7 @@ $::dummyString = "{{{{"; ...@@ -13,6 +13,7 @@ $::dummyString = "{{{{";
# #
my $password = @ARGV[0]; my $password = @ARGV[0];
print $password,"\n"; print $password,"\n";
print encodePassword($password),"\n";
my $scrambled_string = scrambleString($password); my $scrambled_string = scrambleString($password);
print $scrambled_string,"\n"; print $scrambled_string,"\n";
...@@ -83,7 +84,7 @@ sub getRandomValidCharFromList ...@@ -83,7 +84,7 @@ sub getRandomValidCharFromList
my $tm = localtime; my $tm = localtime;
my $k = ($tm->sec); my $k = ($tm->sec);
return 0; return getvalidCharList(0);
} }
...@@ -100,6 +101,7 @@ sub scrambleString ...@@ -100,6 +101,7 @@ sub scrambleString
if (length($str) < 32) if (length($str) < 32)
{ {
$sRet .= $::dummyString; $sRet .= $::dummyString;
print "Added dummy $sRet\n";
} }
for ( my $iR = (length($str) - 1); $iR >= 0; $iR--) for ( my $iR = (length($str) - 1); $iR >= 0; $iR--)
...@@ -108,32 +110,38 @@ sub scrambleString ...@@ -108,32 +110,38 @@ sub scrambleString
#Reverse string. #Reverse string.
# #
$sRet .= substr($str,$iR,1); $sRet .= substr($str,$iR,1);
print "Reverse: $sRet\n";
} }
if (length($sRet) < 32) if (length($sRet) < 32)
{ {
$sRet .= $::dummyString; $sRet .= $::dummyString;
print "Added dummy2 $sRet\n";
} }
my $app=getRandomValidCharFromList(); my $app=getRandomValidCharFromList();
print "Random valid char: $app\n";
my $k=ord($app); my $k=ord($app);
my $l=$k + length($sRet) -2; my $l=$k + length($sRet) -2;
$sRet= $app.$sRet; $sRet= $app.$sRet;
print "Random $sRet\n\n";
for (my $i1 = 1; $i1 < length($sRet); $i1++) for (my $i1 = 1; $i1 < length($sRet); $i1++)
{ {
my $app2=substr($sRet,$i1,1); my $app2=substr($sRet,$i1,1);
print "For cycle app2= $app2\n}";
my $j = findCharInList($app2); my $j = findCharInList($app2);
print "For cícle j= $j\n";
if ($j == -1) if ($j == -1)
{ {
return $sRet; return $sRet;
} }
my $i = ($j + $l * ($i1 + 1)) % $::numValidCharList; my $i = ($j + $l * ($i1 + 1)) % $::numValidCharList;
print "For cícle: i= $i\n";
my $car=getvalidCharList($i); my $car=getvalidCharList($i);
$sRet=substr_replace($sRet,$car,$i1,1); $sRet=substr_replace($sRet,$car,$i1,1);
print "For cycle sRet: $sRet\n\n"
} }
my $c = (ord(getRandomValidCharFromList())) + 2; my $c = (ord(getRandomValidCharFromList())) + 2;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import sys import sys
import random import random
import re import re
from xml.sax.saxutils import escape
numValidCharList = 85 numValidCharList = 85
dummyString = "{{{{" dummyString = "{{{{"
...@@ -51,8 +52,8 @@ def findCharInList(c): ...@@ -51,8 +52,8 @@ def findCharInList(c):
return i return i
def getRandomValidCharFromList(): def getRandomValidCharFromList():
#return getvalidCharList(random.randint(0,60)) return getvalidCharList(random.randint(0,60))
return getvalidCharList(0) #return getvalidCharList(0)
def scrambleString(s): def scrambleString(s):
...@@ -63,24 +64,31 @@ def scrambleString(s): ...@@ -63,24 +64,31 @@ def scrambleString(s):
strp = encodePassword(s) strp = encodePassword(s)
if len(strp) < 32: if len(strp) < 32:
sRet += dummyString sRet += dummyString
for iR in reversed(range(len(strp)-1)): #print "Added dummy "+sRet
for iR in reversed(range(len(strp))):
sRet += strp[iR:iR+1] sRet += strp[iR:iR+1]
#print "Reverse: "+sRet
if len(sRet) < 32: if len(sRet) < 32:
sRet += dummyString sRet += dummyString
#print "Added dummy2 "+sRet
app = getRandomValidCharFromList() app = getRandomValidCharFromList()
#print "Random valid char: "+app
k = ord(app) k = ord(app)
l = k + len(sRet) - 2 l = k + len(sRet) - 2
sRet = app + sRet sRet = app + sRet
#print "Random "+sRet+"\n"
for i1 in range(1, len(sRet)): for i1 in range(1, len(sRet)):
app2 = sRet[i1 : i1 + 1] app2 = sRet[i1 : i1 + 1]
#print "For cycle app2= "+str(app2)
j = findCharInList(app2) j = findCharInList(app2)
#print "For cycle j= "+str(j)
if j == -1: if j == -1:
return sRet return sRet
i = (j + l * (i1 + 1)) % numValidCharList i = (j + l * (i1 + 1)) % numValidCharList
#print "For cycle i= "+str(i)
car = getvalidCharList(i) car = getvalidCharList(i)
sRet = substr_replace(sRet,car,i1,1) sRet = substr_replace(sRet,car,i1,1)
#print "For cycle sRet: "+sRet+"\n"
c = (ord(getRandomValidCharFromList())) + 2 c = (ord(getRandomValidCharFromList())) + 2
c2 = chr(c) c2 = chr(c)
sRet = sRet + c2 sRet = sRet + c2
...@@ -88,18 +96,7 @@ def scrambleString(s): ...@@ -88,18 +96,7 @@ def scrambleString(s):
def URLEncode(url): def URLEncode(url):
theURL = url return escape(url)
#theURL =~ s/&/&amp;/g;
url = re.sub("&","&amp",url)
#theURL =~ s/\"\"/&quot;/g;
url = re.sub("\"","&quot",url)
#theURL =~ s/\'/&#039;/g;
url = re.sub("\"","&quot",url)
#theURL =~ s/</&lt;/g;
url = re.sub("<","&lt",url)
#theURL =~ s/>/&gt;/g;
url = re.sub(">","&gt",url)
return theURL
def substr_replace(in_str,ch,pos,qt): def substr_replace(in_str,ch,pos,qt):
clist = list(in_str) clist = list(in_str)
...@@ -116,6 +113,7 @@ def substr_replace(in_str,ch,pos,qt): ...@@ -116,6 +113,7 @@ def substr_replace(in_str,ch,pos,qt):
if __name__ == "__main__": if __name__ == "__main__":
password = sys.argv[0] password = sys.argv[1]
print password print password
#print encodePassword(password)
print scrambleString(password) print scrambleString(password)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment