Skip to content

Instantly share code, notes, and snippets.

@wodim
Last active October 4, 2015 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wodim/2691044 to your computer and use it in GitHub Desktop.
Save wodim/2691044 to your computer and use it in GitHub Desktop.
Función «descifra» del webchat de IRC-Hispano - Terra
public function descifra(ping:String, claveCifrado:String) : String
{
var t:ByteArray = Base64.decodeToByteArray(ping);
var k:ByteArray = Base64.decodeToByteArray(claveCifrado);
var v:ByteArray = new ByteArray();
k.position = 24;
k.writeBytes(t,0,8);
v.writeBytes(t,8,16);
k.position = 0;
v.position = 0;
var aes:AESKey = new AESKey(k);
aes.decrypt(v);
aes.dispose();
var tmp:String = v.toString().toUpperCase();
var rnd:Random = new Random();
rnd.autoSeed();
var s:ByteArray = new ByteArray();
rnd.nextBytes(s,8);
k = Base64.decodeToByteArray(claveCifrado);
k.position = 24;
k.writeBytes(s,0,8);
k.position = 0;
v.position = 0;
v.writeMultiByte(tmp,"us-ascii");
var aes2:AESKey = new AESKey(k);
aes2.encrypt(v);
aes2.dispose();
var r:ByteArray = new ByteArray();
r.writeBytes(s,0,8);
r.position = 8;
r.writeBytes(v,0,16);
r.position = 0;
var resultado:String = Base64.encodeByteArray(r);
return resultado;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment