void encrypt(u_char *pass) { u_short i,len; u_char key = 0xeb; len = strlen(pass)+1; printf("%.2x%.2x%.2x",0,len,key); pass[0] ^= (key | 'C'); printf("%.2x",pass[0]); for(i = 1;i { pass[i] ^= pass[i-1] ^ key; printf("%.2x", pass[i]); } printf("\n"); }
#!/bin/sh read -s -p "Password: " PASS COUNT=${#PASS} KEY=$(($RANDOM / 128)) echo printf %.4x%.2x $(($COUNT +1 )) $KEY FIRST=1 for ((i = 0; i CHAR=`echo -n ${PASS:i:1} | od -An -i` if [ $FIRST ]; then CH=$(($CHAR ^ ($KEY | 0x43) )) unset FIRST; else CH=$(($CHAR ^ $PREV ^ $KEY)) fi printf %.2x $CH PREV=$CH done echo
public static String encrypt(String str){ int key = new Random().nextInt(255); StringBuffer hash = new StringBuffer(4 + 2 * (str.length() + 1 ) ); hash.append("0000"); for (int i = 0; i hash.append("00"); } String len = Integer.toHexString(str.length() + 1); int pos = 4; hash.replace(pos - len.length(), pos, len); String chString = Integer.toHexString(key); pos += 2; hash.replace(pos - chString.length(), pos, chString); boolean first = true; byte[] strBytes = str.getBytes(); int ch; int prev = 0; byte c; for (int i = 0; i c = strBytes[i]; if (first) { ch = c ^ (key | 0x43); first = false; } else { ch = c ^ prev ^ key; } chString = Integer.toHexString(ch); pos += 2; hash.replace(pos - chString.length(), pos, chString); System.out.println(chString); prev = ch; } return hash.toString(); }
Hi, this is a working code for AutoIT. Which is the one I love!
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.12.1 Author: Peter M. Script Function: Encrypt a plain/text password to the style that Citirx Uses in their appsrv.ini file or .ica files
Thanks to Bernhard Ü., Dieter G. and Uli W. for helping me! Feel free to use this code but keep this header inside your script!#ce ----------------------------------------------------------------------------; Script Start - Add your code below here;Call the function below with the password as string as parameter!Func _encryptcitrix (ByRef $a)$password=$aSRandom(@SEC)$key=Int((255*Random(0,1,0)+1))
$te="0000"For $i = 0 To StringLen($password) $te = $te & "00"Next$strlen = StringLen($password) + 1$position = 4$left=StringMid($te,1,$position-1)$mid=Hex($strlen,8)For $z = 1 To StringLen ($mid) $currstring = StringMid($mid,$z,1) If $currstring <> "0" Then $mid=StringMid($mid,$z) ExitLoop EndIfNext$dummy=StringLen($mid)If $dummy > 2 Then $dummy = 2$right=StringRight($te,((StringLen($te)-StringLen($left))-$dummy))$te=$left & $mid & $right$position = $position + 1$left=StringMid($te,1,$position-1)$mid=Hex($key)For $z = 1 To StringLen ($mid) $currstring = StringMid($mid,$z,1) If $currstring <> "0" Then $mid=StringMid($mid,$z) ExitLoop EndIfNext$dummy=StringLen($mid)If $dummy > 2 Then $dummy = 2$right=StringRight($te,((StringLen($te)-StringLen($left))-$dummy))$te = $left & $mid & $right$first = True$prev = 0For $i = 1 To StringLen ($password) $c = Asc(StringMid($password,$i,2));checken !!!! If $first Then $ch = BitXOR ($c,BitOR($key,Asc("C"))) $first = False Else $ch = BitXOR($c,$prev,$key) EndIf $position = $position + 2 $sh = Hex($ch,2) $left=StringMid($te,1,$position-1) $mid=$sh $dummy=StringLen($mid) If $dummy > 2 Then $dummy = 2 $right=StringRight($te,((StringLen($te)-StringLen($left))-$dummy)) $te = $left & $mid & $right $prev = $chNext$te=StringLower($te)Return $teEndFunc
Thanks to all the previous posters for their code samples.