Section 1
//AuxFunctions (caurina.transitions.AuxFunctions)
package caurina.transitions {
public class AuxFunctions {
public function AuxFunctions(){
super();
}
public static function concatObjects(... _args):Object{
var currentObject:Object;
var prop:String;
var finalObject:Object = {};
var i:int;
while (i < _args.length) {
currentObject = _args[i];
for (prop in currentObject) {
if (currentObject[prop] == null){
delete finalObject[prop];
} else {
finalObject[prop] = currentObject[prop];
};
};
i++;
};
return (finalObject);
}
public static function numberToG(p_num:Number):Number{
return (((p_num & 0xFF00) >> 8));
}
public static function numberToR(p_num:Number):Number{
return (((p_num & 0xFF0000) >> 16));
}
public static function isInArray(p_string:String, p_array:Array):Boolean{
var l:uint = p_array.length;
var i:uint;
while (i < l) {
if (p_array[i] == p_string){
return (true);
};
i++;
};
return (false);
}
public static function getObjectLength(p_object:Object):uint{
var pName:String;
var totalProperties:uint;
for (pName in p_object) {
totalProperties++;
};
return (totalProperties);
}
public static function numberToB(p_num:Number):Number{
return ((p_num & 0xFF));
}
}
}//package caurina.transitions
Section 2
//Equations (caurina.transitions.Equations)
package caurina.transitions {
public class Equations {
public function Equations(){
super();
trace("Equations is a static class and should not be instantiated.");
}
public static function easeOutBounce(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
if (t < (1 / 2.75)){
return (((c * ((7.5625 * t) * t)) + b));
};
if (t < (2 / 2.75)){
t = (t - (1.5 / 2.75));
return (((c * (((7.5625 * t) * t) + 0.75)) + b));
};
if (t < (2.5 / 2.75)){
t = (t - (2.25 / 2.75));
return (((c * (((7.5625 * t) * t) + 0.9375)) + b));
};
t = (t - (2.625 / 2.75));
return (((c * (((7.5625 * t) * t) + 0.984375)) + b));
}
public static function easeInOutElastic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
var s:Number;
if (t == 0){
return (b);
};
t = (t / (d / 2));
if (t == 2){
return ((b + c));
};
var p:Number = (((!(Boolean(p_params))) || (isNaN(p_params.period)))) ? (d * (0.3 * 1.5)) : p_params.period;
var a:Number = (((!(Boolean(p_params))) || (isNaN(p_params.amplitude)))) ? 0 : p_params.amplitude;
if (((!(Boolean(a))) || ((a < Math.abs(c))))){
a = c;
s = (p / 4);
} else {
s = ((p / (2 * Math.PI)) * Math.asin((c / a)));
};
if (t < 1){
--t;
return (((-0.5 * ((a * Math.pow(2, (10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p)))) + b));
};
--t;
return ((((((a * Math.pow(2, (-10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p))) * 0.5) + c) + b));
}
public static function easeInOutQuad(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / (d / 2));
if (t < 1){
return (((((c / 2) * t) * t) + b));
};
--t;
return ((((-(c) / 2) * ((t * (t - 2)) - 1)) + b));
}
public static function easeInOutBounce(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (((easeInBounce((t * 2), 0, c, d) * 0.5) + b));
};
return ((((easeOutBounce(((t * 2) - d), 0, c, d) * 0.5) + (c * 0.5)) + b));
}
public static function easeInOutBack(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
var s:Number = (((!(Boolean(p_params))) || (isNaN(p_params.overshoot)))) ? 1.70158 : p_params.overshoot;
t = (t / (d / 2));
if (t < 1){
s = (s * 1.525);
return ((((c / 2) * ((t * t) * (((s + 1) * t) - s))) + b));
};
t = (t - 2);
s = (s * 1.525);
return ((((c / 2) * (((t * t) * (((s + 1) * t) + s)) + 2)) + b));
}
public static function easeOutInCubic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutCubic((t * 2), b, (c / 2), d, p_params));
};
return (easeInCubic(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeNone(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return ((((c * t) / d) + b));
}
public static function easeOutBack(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
var s:Number = (((!(Boolean(p_params))) || (isNaN(p_params.overshoot)))) ? 1.70158 : p_params.overshoot;
t = ((t / d) - 1);
return (((c * (((t * t) * (((s + 1) * t) + s)) + 1)) + b));
}
public static function easeInOutSine(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return ((((-(c) / 2) * (Math.cos(((Math.PI * t) / d)) - 1)) + b));
}
public static function easeInBack(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
var s:Number = (((!(Boolean(p_params))) || (isNaN(p_params.overshoot)))) ? 1.70158 : p_params.overshoot;
t = (t / d);
return (((((c * t) * t) * (((s + 1) * t) - s)) + b));
}
public static function easeInQuart(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
return ((((((c * t) * t) * t) * t) + b));
}
public static function easeOutInQuint(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutQuint((t * 2), b, (c / 2), d, p_params));
};
return (easeInQuint(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeOutInBounce(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutBounce((t * 2), b, (c / 2), d, p_params));
};
return (easeInBounce(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function init():void{
Tweener.registerTransition("easenone", easeNone);
Tweener.registerTransition("linear", easeNone);
Tweener.registerTransition("easeinquad", easeInQuad);
Tweener.registerTransition("easeoutquad", easeOutQuad);
Tweener.registerTransition("easeinoutquad", easeInOutQuad);
Tweener.registerTransition("easeoutinquad", easeOutInQuad);
Tweener.registerTransition("easeincubic", easeInCubic);
Tweener.registerTransition("easeoutcubic", easeOutCubic);
Tweener.registerTransition("easeinoutcubic", easeInOutCubic);
Tweener.registerTransition("easeoutincubic", easeOutInCubic);
Tweener.registerTransition("easeinquart", easeInQuart);
Tweener.registerTransition("easeoutquart", easeOutQuart);
Tweener.registerTransition("easeinoutquart", easeInOutQuart);
Tweener.registerTransition("easeoutinquart", easeOutInQuart);
Tweener.registerTransition("easeinquint", easeInQuint);
Tweener.registerTransition("easeoutquint", easeOutQuint);
Tweener.registerTransition("easeinoutquint", easeInOutQuint);
Tweener.registerTransition("easeoutinquint", easeOutInQuint);
Tweener.registerTransition("easeinsine", easeInSine);
Tweener.registerTransition("easeoutsine", easeOutSine);
Tweener.registerTransition("easeinoutsine", easeInOutSine);
Tweener.registerTransition("easeoutinsine", easeOutInSine);
Tweener.registerTransition("easeincirc", easeInCirc);
Tweener.registerTransition("easeoutcirc", easeOutCirc);
Tweener.registerTransition("easeinoutcirc", easeInOutCirc);
Tweener.registerTransition("easeoutincirc", easeOutInCirc);
Tweener.registerTransition("easeinexpo", easeInExpo);
Tweener.registerTransition("easeoutexpo", easeOutExpo);
Tweener.registerTransition("easeinoutexpo", easeInOutExpo);
Tweener.registerTransition("easeoutinexpo", easeOutInExpo);
Tweener.registerTransition("easeinelastic", easeInElastic);
Tweener.registerTransition("easeoutelastic", easeOutElastic);
Tweener.registerTransition("easeinoutelastic", easeInOutElastic);
Tweener.registerTransition("easeoutinelastic", easeOutInElastic);
Tweener.registerTransition("easeinback", easeInBack);
Tweener.registerTransition("easeoutback", easeOutBack);
Tweener.registerTransition("easeinoutback", easeInOutBack);
Tweener.registerTransition("easeoutinback", easeOutInBack);
Tweener.registerTransition("easeinbounce", easeInBounce);
Tweener.registerTransition("easeoutbounce", easeOutBounce);
Tweener.registerTransition("easeinoutbounce", easeInOutBounce);
Tweener.registerTransition("easeoutinbounce", easeOutInBounce);
}
public static function easeOutExpo(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return (((t)==d) ? (b + c) : (((c * 1.001) * (-(Math.pow(2, ((-10 * t) / d))) + 1)) + b));
}
public static function easeOutInBack(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutBack((t * 2), b, (c / 2), d, p_params));
};
return (easeInBack(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeInExpo(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return (((t)==0) ? b : (((c * Math.pow(2, (10 * ((t / d) - 1)))) + b) - (c * 0.001)));
}
public static function easeInCubic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
return (((((c * t) * t) * t) + b));
}
public static function easeInQuint(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
return (((((((c * t) * t) * t) * t) * t) + b));
}
public static function easeInOutCirc(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / (d / 2));
if (t < 1){
return ((((-(c) / 2) * (Math.sqrt((1 - (t * t))) - 1)) + b));
};
t = (t - 2);
return ((((c / 2) * (Math.sqrt((1 - (t * t))) + 1)) + b));
}
public static function easeInQuad(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
return ((((c * t) * t) + b));
}
public static function easeInBounce(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return (((c - easeOutBounce((d - t), 0, c, d)) + b));
}
public static function easeOutInExpo(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutExpo((t * 2), b, (c / 2), d, p_params));
};
return (easeInExpo(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeOutQuart(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = ((t / d) - 1);
return (((-(c) * ((((t * t) * t) * t) - 1)) + b));
}
public static function easeInSine(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return ((((-(c) * Math.cos(((t / d) * (Math.PI / 2)))) + c) + b));
}
public static function easeInOutQuart(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / (d / 2));
if (t < 1){
return (((((((c / 2) * t) * t) * t) * t) + b));
};
t = (t - 2);
return ((((-(c) / 2) * ((((t * t) * t) * t) - 2)) + b));
}
public static function easeOutQuad(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
return ((((-(c) * t) * (t - 2)) + b));
}
public static function easeOutInElastic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutElastic((t * 2), b, (c / 2), d, p_params));
};
return (easeInElastic(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeInElastic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
var s:Number;
if (t == 0){
return (b);
};
t = (t / d);
if (t == 1){
return ((b + c));
};
var p:Number = (((!(Boolean(p_params))) || (isNaN(p_params.period)))) ? (d * 0.3) : p_params.period;
var a:Number = (((!(Boolean(p_params))) || (isNaN(p_params.amplitude)))) ? 0 : p_params.amplitude;
if (((!(Boolean(a))) || ((a < Math.abs(c))))){
a = c;
s = (p / 4);
} else {
s = ((p / (2 * Math.PI)) * Math.asin((c / a)));
};
--t;
return ((-(((a * Math.pow(2, (10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p)))) + b));
}
public static function easeOutCubic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = ((t / d) - 1);
return (((c * (((t * t) * t) + 1)) + b));
}
public static function easeOutQuint(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = ((t / d) - 1);
return (((c * (((((t * t) * t) * t) * t) + 1)) + b));
}
public static function easeOutInQuad(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutQuad((t * 2), b, (c / 2), d, p_params));
};
return (easeInQuad(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeOutSine(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
return (((c * Math.sin(((t / d) * (Math.PI / 2)))) + b));
}
public static function easeInOutCubic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / (d / 2));
if (t < 1){
return ((((((c / 2) * t) * t) * t) + b));
};
t = (t - 2);
return ((((c / 2) * (((t * t) * t) + 2)) + b));
}
public static function easeInOutQuint(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / (d / 2));
if (t < 1){
return ((((((((c / 2) * t) * t) * t) * t) * t) + b));
};
t = (t - 2);
return ((((c / 2) * (((((t * t) * t) * t) * t) + 2)) + b));
}
public static function easeInCirc(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = (t / d);
return (((-(c) * (Math.sqrt((1 - (t * t))) - 1)) + b));
}
public static function easeOutInSine(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutSine((t * 2), b, (c / 2), d, p_params));
};
return (easeInSine(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeInOutExpo(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t == 0){
return (b);
};
if (t == d){
return ((b + c));
};
t = (t / (d / 2));
if (t < 1){
return (((((c / 2) * Math.pow(2, (10 * (t - 1)))) + b) - (c * 0.0005)));
};
--t;
return (((((c / 2) * 1.0005) * (-(Math.pow(2, (-10 * t))) + 2)) + b));
}
public static function easeOutElastic(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
var s:Number;
if (t == 0){
return (b);
};
t = (t / d);
if (t == 1){
return ((b + c));
};
var p:Number = (((!(Boolean(p_params))) || (isNaN(p_params.period)))) ? (d * 0.3) : p_params.period;
var a:Number = (((!(Boolean(p_params))) || (isNaN(p_params.amplitude)))) ? 0 : p_params.amplitude;
if (((!(Boolean(a))) || ((a < Math.abs(c))))){
a = c;
s = (p / 4);
} else {
s = ((p / (2 * Math.PI)) * Math.asin((c / a)));
};
return (((((a * Math.pow(2, (-10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p))) + c) + b));
}
public static function easeOutCirc(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
t = ((t / d) - 1);
return (((c * Math.sqrt((1 - (t * t)))) + b));
}
public static function easeOutInQuart(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutQuart((t * 2), b, (c / 2), d, p_params));
};
return (easeInQuart(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
public static function easeOutInCirc(t:Number, b:Number, c:Number, d:Number, p_params:Object=null):Number{
if (t < (d / 2)){
return (easeOutCirc((t * 2), b, (c / 2), d, p_params));
};
return (easeInCirc(((t * 2) - d), (b + (c / 2)), (c / 2), d, p_params));
}
}
}//package caurina.transitions
Section 3
//PropertyInfoObj (caurina.transitions.PropertyInfoObj)
package caurina.transitions {
public class PropertyInfoObj {
public var modifierParameters:Array;
public var isSpecialProperty:Boolean;
public var valueComplete:Number;
public var modifierFunction:Function;
public var extra:Object;
public var valueStart:Number;
public var hasModifier:Boolean;
public var arrayIndex:Number;
public var originalValueComplete:Object;
public function PropertyInfoObj(p_valueStart:Number, p_valueComplete:Number, p_originalValueComplete:Object, p_arrayIndex:Number, p_extra:Object, p_isSpecialProperty:Boolean, p_modifierFunction:Function, p_modifierParameters:Array){
super();
valueStart = p_valueStart;
valueComplete = p_valueComplete;
originalValueComplete = p_originalValueComplete;
arrayIndex = p_arrayIndex;
extra = p_extra;
isSpecialProperty = p_isSpecialProperty;
hasModifier = Boolean(p_modifierFunction);
modifierFunction = p_modifierFunction;
modifierParameters = p_modifierParameters;
}
public function toString():String{
var returnStr:String = "\n[PropertyInfoObj ";
returnStr = (returnStr + ("valueStart:" + String(valueStart)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("valueComplete:" + String(valueComplete)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("originalValueComplete:" + String(originalValueComplete)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("arrayIndex:" + String(arrayIndex)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("extra:" + String(extra)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("isSpecialProperty:" + String(isSpecialProperty)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("hasModifier:" + String(hasModifier)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("modifierFunction:" + String(modifierFunction)));
returnStr = (returnStr + ", ");
returnStr = (returnStr + ("modifierParameters:" + String(modifierParameters)));
returnStr = (returnStr + "]\n");
return (returnStr);
}
public function clone():PropertyInfoObj{
var nProperty:PropertyInfoObj = new PropertyInfoObj(valueStart, valueComplete, originalValueComplete, arrayIndex, extra, isSpecialProperty, modifierFunction, modifierParameters);
return (nProperty);
}
}
}//package caurina.transitions
Section 4
//SpecialProperty (caurina.transitions.SpecialProperty)
package caurina.transitions {
public class SpecialProperty {
public var parameters:Array;
public var getValue:Function;
public var preProcess:Function;
public var setValue:Function;
public function SpecialProperty(p_getFunction:Function, p_setFunction:Function, p_parameters:Array=null, p_preProcessFunction:Function=null){
super();
getValue = p_getFunction;
setValue = p_setFunction;
parameters = p_parameters;
preProcess = p_preProcessFunction;
}
public function toString():String{
var value:String = "";
value = (value + "[SpecialProperty ");
value = (value + ("getValue:" + String(getValue)));
value = (value + ", ");
value = (value + ("setValue:" + String(setValue)));
value = (value + ", ");
value = (value + ("parameters:" + String(parameters)));
value = (value + ", ");
value = (value + ("preProcess:" + String(preProcess)));
value = (value + "]");
return (value);
}
}
}//package caurina.transitions
Section 5
//SpecialPropertyModifier (caurina.transitions.SpecialPropertyModifier)
package caurina.transitions {
public class SpecialPropertyModifier {
public var getValue:Function;
public var modifyValues:Function;
public function SpecialPropertyModifier(p_modifyFunction:Function, p_getFunction:Function){
super();
modifyValues = p_modifyFunction;
getValue = p_getFunction;
}
public function toString():String{
var value:String = "";
value = (value + "[SpecialPropertyModifier ");
value = (value + ("modifyValues:" + String(modifyValues)));
value = (value + ", ");
value = (value + ("getValue:" + String(getValue)));
value = (value + "]");
return (value);
}
}
}//package caurina.transitions
Section 6
//SpecialPropertySplitter (caurina.transitions.SpecialPropertySplitter)
package caurina.transitions {
public class SpecialPropertySplitter {
public var parameters:Array;
public var splitValues:Function;
public function SpecialPropertySplitter(p_splitFunction:Function, p_parameters:Array){
super();
splitValues = p_splitFunction;
parameters = p_parameters;
}
public function toString():String{
var value:String = "";
value = (value + "[SpecialPropertySplitter ");
value = (value + ("splitValues:" + String(splitValues)));
value = (value + ", ");
value = (value + ("parameters:" + String(parameters)));
value = (value + "]");
return (value);
}
}
}//package caurina.transitions
Section 7
//Tweener (caurina.transitions.Tweener)
package caurina.transitions {
import flash.events.*;
import flash.utils.*;
import flash.display.*;
public class Tweener {
private static var _timeScale:Number = 1;
private static var _currentTimeFrame:Number;
private static var _specialPropertySplitterList:Object;
private static var _engineExists:Boolean = false;
private static var _specialPropertyModifierList:Object;
private static var _currentTime:Number;
private static var _tweenList:Array;
private static var _specialPropertyList:Object;
private static var _transitionList:Object;
private static var _inited:Boolean = false;
private static var __tweener_controller__:MovieClip;
public function Tweener(){
super();
trace("Tweener is a static class and should not be instantiated.");
}
public static function registerSpecialPropertyModifier(p_name:String, p_modifyFunction:Function, p_getFunction:Function):void{
if (!_inited){
init();
};
var spm:SpecialPropertyModifier = new SpecialPropertyModifier(p_modifyFunction, p_getFunction);
_specialPropertyModifierList[p_name] = spm;
}
public static function registerSpecialProperty(p_name:String, p_getFunction:Function, p_setFunction:Function, p_parameters:Array=null, p_preProcessFunction:Function=null):void{
if (!_inited){
init();
};
var sp:SpecialProperty = new SpecialProperty(p_getFunction, p_setFunction, p_parameters, p_preProcessFunction);
_specialPropertyList[p_name] = sp;
}
public static function init(p_object=null):void{
_inited = true;
_transitionList = new Object();
Equations.init();
_specialPropertyList = new Object();
_specialPropertyModifierList = new Object();
_specialPropertySplitterList = new Object();
}
private static function updateTweens():Boolean{
var i:int;
if (_tweenList.length == 0){
return (false);
};
i = 0;
while (i < _tweenList.length) {
if ((((_tweenList[i] == undefined)) || (!(_tweenList[i].isPaused)))){
if (!updateTweenByIndex(i)){
removeTweenByIndex(i);
};
if (_tweenList[i] == null){
removeTweenByIndex(i, true);
i--;
};
};
i++;
};
return (true);
}
public static function addCaller(p_scopes:Object=null, p_parameters:Object=null):Boolean{
var i:Number;
var rScopes:Array;
var rTransition:Function;
var nTween:TweenListObj;
var myT:Number;
var trans:String;
if (!Boolean(p_scopes)){
return (false);
};
if ((p_scopes is Array)){
rScopes = p_scopes.concat();
} else {
rScopes = [p_scopes];
};
var p_obj:Object = p_parameters;
if (!_inited){
init();
};
if (((!(_engineExists)) || (!(Boolean(__tweener_controller__))))){
startEngine();
};
var rTime:Number = (isNaN(p_obj.time)) ? 0 : p_obj.time;
var rDelay:Number = (isNaN(p_obj.delay)) ? 0 : p_obj.delay;
if (typeof(p_obj.transition) == "string"){
trans = p_obj.transition.toLowerCase();
rTransition = _transitionList[trans];
} else {
rTransition = p_obj.transition;
};
if (!Boolean(rTransition)){
rTransition = _transitionList["easeoutexpo"];
};
i = 0;
while (i < rScopes.length) {
if (p_obj.useFrames == true){
nTween = new TweenListObj(rScopes[i], (_currentTimeFrame + (rDelay / _timeScale)), (_currentTimeFrame + ((rDelay + rTime) / _timeScale)), true, rTransition, p_obj.transitionParams);
} else {
nTween = new TweenListObj(rScopes[i], (_currentTime + ((rDelay * 1000) / _timeScale)), (_currentTime + (((rDelay * 1000) + (rTime * 1000)) / _timeScale)), false, rTransition, p_obj.transitionParams);
};
nTween.properties = null;
nTween.onStart = p_obj.onStart;
nTween.onUpdate = p_obj.onUpdate;
nTween.onComplete = p_obj.onComplete;
nTween.onOverwrite = p_obj.onOverwrite;
nTween.onStartParams = p_obj.onStartParams;
nTween.onUpdateParams = p_obj.onUpdateParams;
nTween.onCompleteParams = p_obj.onCompleteParams;
nTween.onOverwriteParams = p_obj.onOverwriteParams;
nTween.onStartScope = p_obj.onStartScope;
nTween.onUpdateScope = p_obj.onUpdateScope;
nTween.onCompleteScope = p_obj.onCompleteScope;
nTween.onOverwriteScope = p_obj.onOverwriteScope;
nTween.onErrorScope = p_obj.onErrorScope;
nTween.isCaller = true;
nTween.count = p_obj.count;
nTween.waitFrames = p_obj.waitFrames;
_tweenList.push(nTween);
if ((((rTime == 0)) && ((rDelay == 0)))){
myT = (_tweenList.length - 1);
updateTweenByIndex(myT);
removeTweenByIndex(myT);
};
i++;
};
return (true);
}
public static function pauseAllTweens():Boolean{
var i:uint;
if (!Boolean(_tweenList)){
return (false);
};
var paused:Boolean;
i = 0;
while (i < _tweenList.length) {
pauseTweenByIndex(i);
paused = true;
i++;
};
return (paused);
}
public static function removeTweens(p_scope:Object, ... _args):Boolean{
var i:uint;
var properties:Array = new Array();
i = 0;
while (i < _args.length) {
if ((((typeof(_args[i]) == "string")) && (!(AuxFunctions.isInArray(_args[i], properties))))){
properties.push(_args[i]);
};
i++;
};
return (affectTweens(removeTweenByIndex, p_scope, properties));
}
public static function splitTweens(p_tween:Number, p_properties:Array):uint{
var i:uint;
var pName:String;
var found:Boolean;
var originalTween:TweenListObj = _tweenList[p_tween];
var newTween:TweenListObj = originalTween.clone(false);
i = 0;
while (i < p_properties.length) {
pName = p_properties[i];
if (Boolean(originalTween.properties[pName])){
originalTween.properties[pName] = undefined;
delete originalTween.properties[pName];
};
i++;
};
for (pName in newTween.properties) {
found = false;
i = 0;
while (i < p_properties.length) {
if (p_properties[i] == pName){
found = true;
break;
};
i++;
};
if (!found){
newTween.properties[pName] = undefined;
delete newTween.properties[pName];
};
};
_tweenList.push(newTween);
return ((_tweenList.length - 1));
}
public static function updateFrame():void{
_currentTimeFrame++;
}
public static function resumeTweenByIndex(p_tween:Number):Boolean{
var tTweening:TweenListObj = _tweenList[p_tween];
if ((((tTweening == null)) || (!(tTweening.isPaused)))){
return (false);
};
var cTime:Number = getCurrentTweeningTime(tTweening);
tTweening.timeStart = (tTweening.timeStart + (cTime - tTweening.timePaused));
tTweening.timeComplete = (tTweening.timeComplete + (cTime - tTweening.timePaused));
tTweening.timePaused = undefined;
tTweening.isPaused = false;
return (true);
}
public static function getVersion():String{
return ("AS3 1.31.69");
}
public static function onEnterFrame(e:Event):void{
updateTime();
updateFrame();
var hasUpdated:Boolean;
hasUpdated = updateTweens();
if (!hasUpdated){
stopEngine();
};
}
public static function updateTime():void{
_currentTime = getTimer();
}
private static function updateTweenByIndex(i:Number):Boolean{
var tTweening:TweenListObj;
var mustUpdate:Boolean;
var nv:Number;
var t:Number;
var b:Number;
var c:Number;
var d:Number;
var pName:String;
var eventScope:Object;
var tScope:Object;
var tProperty:Object;
var pv:Number;
var i = i;
tTweening = _tweenList[i];
if ((((tTweening == null)) || (!(Boolean(tTweening.scope))))){
return (false);
};
var isOver:Boolean;
var cTime:Number = getCurrentTweeningTime(tTweening);
if (cTime >= tTweening.timeStart){
tScope = tTweening.scope;
if (tTweening.isCaller){
do {
t = (((tTweening.timeComplete - tTweening.timeStart) / tTweening.count) * (tTweening.timesCalled + 1));
b = tTweening.timeStart;
c = (tTweening.timeComplete - tTweening.timeStart);
d = (tTweening.timeComplete - tTweening.timeStart);
nv = tTweening.transition(t, b, c, d);
//unresolved if
if (Boolean(tTweening.onUpdate)){
eventScope = (Boolean(tTweening.onUpdateScope)) ? tTweening.onUpdateScope : tScope;
tTweening.onUpdate.apply(eventScope, tTweening.onUpdateParams);
continue;
var _slot1 = e;
handleError(tTweening, _slot1, "onUpdate");
};
} while (tTweening.timesCalled++, !(tTweening.timesCalled >= tTweening.count));
} else {
mustUpdate = (((((tTweening.skipUpdates < 1)) || (!(tTweening.skipUpdates)))) || ((tTweening.updatesSkipped >= tTweening.skipUpdates)));
if (cTime >= tTweening.timeComplete){
isOver = true;
mustUpdate = true;
};
if (!tTweening.hasStarted){
if (Boolean(tTweening.onStart)){
eventScope = (Boolean(tTweening.onStartScope)) ? tTweening.onStartScope : tScope;
tTweening.onStart.apply(eventScope, tTweening.onStartParams);
//unresolved jump
var _slot1 = e;
handleError(tTweening, _slot1, "onStart");
};
for (pName in tTweening.properties) {
if (tTweening.properties[pName].isSpecialProperty){
if (Boolean(_specialPropertyList[pName].preProcess)){
tTweening.properties[pName].valueComplete = _specialPropertyList[pName].preProcess(tScope, _specialPropertyList[pName].parameters, tTweening.properties[pName].originalValueComplete, tTweening.properties[pName].extra);
};
pv = _specialPropertyList[pName].getValue(tScope, _specialPropertyList[pName].parameters, tTweening.properties[pName].extra);
} else {
pv = tScope[pName];
};
tTweening.properties[pName].valueStart = (isNaN(pv)) ? tTweening.properties[pName].valueComplete : pv;
};
mustUpdate = true;
tTweening.hasStarted = true;
};
if (mustUpdate){
for (pName in tTweening.properties) {
tProperty = tTweening.properties[pName];
if (isOver){
nv = tProperty.valueComplete;
} else {
if (tProperty.hasModifier){
t = (cTime - tTweening.timeStart);
d = (tTweening.timeComplete - tTweening.timeStart);
nv = tTweening.transition(t, 0, 1, d, tTweening.transitionParams);
nv = tProperty.modifierFunction(tProperty.valueStart, tProperty.valueComplete, nv, tProperty.modifierParameters);
} else {
t = (cTime - tTweening.timeStart);
b = tProperty.valueStart;
c = (tProperty.valueComplete - tProperty.valueStart);
d = (tTweening.timeComplete - tTweening.timeStart);
nv = tTweening.transition(t, b, c, d, tTweening.transitionParams);
};
};
if (tTweening.rounded){
nv = Math.round(nv);
};
if (tProperty.isSpecialProperty){
_specialPropertyList[pName].setValue(tScope, nv, _specialPropertyList[pName].parameters, tTweening.properties[pName].extra);
} else {
tScope[pName] = nv;
};
};
tTweening.updatesSkipped = 0;
if (Boolean(tTweening.onUpdate)){
eventScope = (Boolean(tTweening.onUpdateScope)) ? tTweening.onUpdateScope : tScope;
tTweening.onUpdate.apply(eventScope, tTweening.onUpdateParams);
//unresolved jump
var _slot1 = e;
handleError(tTweening, _slot1, "onUpdate");
};
} else {
tTweening.updatesSkipped++;
};
};
if (((isOver) && (Boolean(tTweening.onComplete)))){
eventScope = (Boolean(tTweening.onCompleteScope)) ? tTweening.onCompleteScope : tScope;
tTweening.onComplete.apply(eventScope, tTweening.onCompleteParams);
//unresolved jump
var _slot1 = e;
handleError(tTweening, _slot1, "onComplete");
};
return (!(isOver));
};
return (true);
}
public static function setTimeScale(p_time:Number):void{
var i:Number;
var cTime:Number;
if (isNaN(p_time)){
p_time = 1;
};
if (p_time < 1E-5){
p_time = 1E-5;
};
if (p_time != _timeScale){
if (_tweenList != null){
i = 0;
while (i < _tweenList.length) {
cTime = getCurrentTweeningTime(_tweenList[i]);
_tweenList[i].timeStart = (cTime - (((cTime - _tweenList[i].timeStart) * _timeScale) / p_time));
_tweenList[i].timeComplete = (cTime - (((cTime - _tweenList[i].timeComplete) * _timeScale) / p_time));
if (_tweenList[i].timePaused != undefined){
_tweenList[i].timePaused = (cTime - (((cTime - _tweenList[i].timePaused) * _timeScale) / p_time));
};
i++;
};
};
_timeScale = p_time;
};
}
public static function resumeAllTweens():Boolean{
var i:uint;
if (!Boolean(_tweenList)){
return (false);
};
var resumed:Boolean;
i = 0;
while (i < _tweenList.length) {
resumeTweenByIndex(i);
resumed = true;
i++;
};
return (resumed);
}
private static function handleError(pTweening:TweenListObj, pError:Error, pCallBackName:String):void{
var eventScope:Object;
var pTweening = pTweening;
var pError = pError;
var pCallBackName = pCallBackName;
if (((Boolean(pTweening.onError)) && ((pTweening.onError is Function)))){
eventScope = (Boolean(pTweening.onErrorScope)) ? pTweening.onErrorScope : pTweening.scope;
pTweening.onError.apply(pTweening.scope, [pTweening.scope, pError]);
//unresolved jump
var _slot1 = metaError;
printError(((((String(pTweening.scope) + " raised an error while executing the 'onError' handler. Original error:\n ") + pError.getStackTrace()) + "\nonError error: ") + _slot1.getStackTrace()));
} else {
if (!Boolean(pTweening.onError)){
printError(((((String(pTweening.scope) + " raised an error while executing the '") + pCallBackName) + "'handler. \n") + pError.getStackTrace()));
};
};
}
private static function startEngine():void{
_engineExists = true;
_tweenList = new Array();
__tweener_controller__ = new MovieClip();
__tweener_controller__.addEventListener(Event.ENTER_FRAME, Tweener.onEnterFrame);
_currentTimeFrame = 0;
updateTime();
}
public static function removeAllTweens():Boolean{
var i:uint;
if (!Boolean(_tweenList)){
return (false);
};
var removed:Boolean;
i = 0;
while (i < _tweenList.length) {
removeTweenByIndex(i);
removed = true;
i++;
};
return (removed);
}
public static function addTween(p_scopes:Object=null, p_parameters:Object=null):Boolean{
var i:Number;
var j:Number;
var istr:String;
var rScopes:Array;
var rTransition:Function;
var nProperties:Object;
var nTween:TweenListObj;
var myT:Number;
var splitProperties:Array;
var splitProperties2:Array;
var tempModifiedProperties:Array;
var trans:String;
if (!Boolean(p_scopes)){
return (false);
};
if ((p_scopes is Array)){
rScopes = p_scopes.concat();
} else {
rScopes = [p_scopes];
};
var p_obj:Object = TweenListObj.makePropertiesChain(arguments[(arguments.length - 1)]);
if (!_inited){
init();
};
if (((!(_engineExists)) || (!(Boolean(__tweener_controller__))))){
startEngine();
};
var rTime:Number = (isNaN(p_obj.time)) ? 0 : p_obj.time;
var rDelay:Number = (isNaN(p_obj.delay)) ? 0 : p_obj.delay;
var rProperties:Array = new Array();
var restrictedWords:Object = {time:true, delay:true, useFrames:true, skipUpdates:true, transition:true, transitionParams:true, onStart:true, onUpdate:true, onComplete:true, onOverwrite:true, onError:true, rounded:true, onStartParams:true, onUpdateParams:true, onCompleteParams:true, onOverwriteParams:true, onStartScope:true, onUpdateScope:true, onCompleteScope:true, onOverwriteScope:true, onErrorScope:true};
var modifiedProperties:Object = new Object();
for (istr in p_obj) {
if (!restrictedWords[istr]){
if (_specialPropertySplitterList[istr]){
splitProperties = _specialPropertySplitterList[istr].splitValues(p_obj[istr], _specialPropertySplitterList[istr].parameters);
i = 0;
while (i < splitProperties.length) {
if (_specialPropertySplitterList[splitProperties[i].name]){
splitProperties2 = _specialPropertySplitterList[splitProperties[i].name].splitValues(splitProperties[i].value, _specialPropertySplitterList[splitProperties[i].name].parameters);
j = 0;
while (j < splitProperties2.length) {
rProperties[splitProperties2[j].name] = {valueStart:undefined, valueComplete:splitProperties2[j].value, arrayIndex:splitProperties2[j].arrayIndex, isSpecialProperty:false};
j++;
};
} else {
rProperties[splitProperties[i].name] = {valueStart:undefined, valueComplete:splitProperties[i].value, arrayIndex:splitProperties[i].arrayIndex, isSpecialProperty:false};
};
i++;
};
} else {
if (_specialPropertyModifierList[istr] != undefined){
tempModifiedProperties = _specialPropertyModifierList[istr].modifyValues(p_obj[istr]);
i = 0;
while (i < tempModifiedProperties.length) {
modifiedProperties[tempModifiedProperties[i].name] = {modifierParameters:tempModifiedProperties[i].parameters, modifierFunction:_specialPropertyModifierList[istr].getValue};
i++;
};
} else {
rProperties[istr] = {valueStart:undefined, valueComplete:p_obj[istr]};
};
};
};
};
for (istr in rProperties) {
if (_specialPropertyList[istr] != undefined){
rProperties[istr].isSpecialProperty = true;
} else {
if (rScopes[0][istr] == undefined){
printError((((("The property '" + istr) + "' doesn't seem to be a normal object property of ") + String(rScopes[0])) + " or a registered special property."));
};
};
};
for (istr in modifiedProperties) {
if (rProperties[istr] != undefined){
rProperties[istr].modifierParameters = modifiedProperties[istr].modifierParameters;
rProperties[istr].modifierFunction = modifiedProperties[istr].modifierFunction;
};
};
if (typeof(p_obj.transition) == "string"){
trans = p_obj.transition.toLowerCase();
rTransition = _transitionList[trans];
} else {
rTransition = p_obj.transition;
};
if (!Boolean(rTransition)){
rTransition = _transitionList["easeoutexpo"];
};
i = 0;
while (i < rScopes.length) {
nProperties = new Object();
for (istr in rProperties) {
nProperties[istr] = new PropertyInfoObj(rProperties[istr].valueStart, rProperties[istr].valueComplete, rProperties[istr].valueComplete, rProperties[istr].arrayIndex, {}, rProperties[istr].isSpecialProperty, rProperties[istr].modifierFunction, rProperties[istr].modifierParameters);
};
if (p_obj.useFrames == true){
nTween = new TweenListObj(rScopes[i], (_currentTimeFrame + (rDelay / _timeScale)), (_currentTimeFrame + ((rDelay + rTime) / _timeScale)), true, rTransition, p_obj.transitionParams);
} else {
nTween = new TweenListObj(rScopes[i], (_currentTime + ((rDelay * 1000) / _timeScale)), (_currentTime + (((rDelay * 1000) + (rTime * 1000)) / _timeScale)), false, rTransition, p_obj.transitionParams);
};
nTween.properties = nProperties;
nTween.onStart = p_obj.onStart;
nTween.onUpdate = p_obj.onUpdate;
nTween.onComplete = p_obj.onComplete;
nTween.onOverwrite = p_obj.onOverwrite;
nTween.onError = p_obj.onError;
nTween.onStartParams = p_obj.onStartParams;
nTween.onUpdateParams = p_obj.onUpdateParams;
nTween.onCompleteParams = p_obj.onCompleteParams;
nTween.onOverwriteParams = p_obj.onOverwriteParams;
nTween.onStartScope = p_obj.onStartScope;
nTween.onUpdateScope = p_obj.onUpdateScope;
nTween.onCompleteScope = p_obj.onCompleteScope;
nTween.onOverwriteScope = p_obj.onOverwriteScope;
nTween.onErrorScope = p_obj.onErrorScope;
nTween.rounded = p_obj.rounded;
nTween.skipUpdates = p_obj.skipUpdates;
removeTweensByTime(nTween.scope, nTween.properties, nTween.timeStart, nTween.timeComplete);
_tweenList.push(nTween);
if ((((rTime == 0)) && ((rDelay == 0)))){
myT = (_tweenList.length - 1);
updateTweenByIndex(myT);
removeTweenByIndex(myT);
};
i++;
};
return (true);
}
public static function registerTransition(p_name:String, p_function:Function):void{
if (!_inited){
init();
};
_transitionList[p_name] = p_function;
}
public static function printError(p_message:String):void{
trace(("## [Tweener] Error: " + p_message));
}
private static function affectTweens(p_affectFunction:Function, p_scope:Object, p_properties:Array):Boolean{
var i:uint;
var affectedProperties:Array;
var j:uint;
var objectProperties:uint;
var slicedTweenIndex:uint;
var affected:Boolean;
if (!Boolean(_tweenList)){
return (false);
};
i = 0;
while (i < _tweenList.length) {
if (((_tweenList[i]) && ((_tweenList[i].scope == p_scope)))){
if (p_properties.length == 0){
p_affectFunction(i);
affected = true;
} else {
affectedProperties = new Array();
j = 0;
while (j < p_properties.length) {
if (Boolean(_tweenList[i].properties[p_properties[j]])){
affectedProperties.push(p_properties[j]);
};
j++;
};
if (affectedProperties.length > 0){
objectProperties = AuxFunctions.getObjectLength(_tweenList[i].properties);
if (objectProperties == affectedProperties.length){
p_affectFunction(i);
affected = true;
} else {
slicedTweenIndex = splitTweens(i, affectedProperties);
p_affectFunction(slicedTweenIndex);
affected = true;
};
};
};
};
i++;
};
return (affected);
}
public static function getTweens(p_scope:Object):Array{
var i:uint;
var pName:String;
if (!Boolean(_tweenList)){
return ([]);
};
var tList:Array = new Array();
i = 0;
while (i < _tweenList.length) {
if (((Boolean(_tweenList[i])) && ((_tweenList[i].scope == p_scope)))){
for (pName in _tweenList[i].properties) {
tList.push(pName);
};
};
i++;
};
return (tList);
}
public static function isTweening(p_scope:Object):Boolean{
var i:uint;
if (!Boolean(_tweenList)){
return (false);
};
i = 0;
while (i < _tweenList.length) {
if (((Boolean(_tweenList[i])) && ((_tweenList[i].scope == p_scope)))){
return (true);
};
i++;
};
return (false);
}
public static function pauseTweenByIndex(p_tween:Number):Boolean{
var tTweening:TweenListObj = _tweenList[p_tween];
if ((((tTweening == null)) || (tTweening.isPaused))){
return (false);
};
tTweening.timePaused = getCurrentTweeningTime(tTweening);
tTweening.isPaused = true;
return (true);
}
public static function getCurrentTweeningTime(p_tweening:Object):Number{
return ((p_tweening.useFrames) ? _currentTimeFrame : _currentTime);
}
public static function getTweenCount(p_scope:Object):Number{
var i:uint;
if (!Boolean(_tweenList)){
return (0);
};
var c:Number = 0;
i = 0;
while (i < _tweenList.length) {
if (((Boolean(_tweenList[i])) && ((_tweenList[i].scope == p_scope)))){
c = (c + AuxFunctions.getObjectLength(_tweenList[i].properties));
};
i++;
};
return (c);
}
private static function stopEngine():void{
_engineExists = false;
_tweenList = null;
_currentTime = 0;
_currentTimeFrame = 0;
__tweener_controller__.removeEventListener(Event.ENTER_FRAME, Tweener.onEnterFrame);
__tweener_controller__ = null;
}
public static function removeTweensByTime(p_scope:Object, p_properties:Object, p_timeStart:Number, p_timeComplete:Number):Boolean{
var removedLocally:Boolean;
var i:uint;
var pName:String;
var eventScope:Object;
var p_scope = p_scope;
var p_properties = p_properties;
var p_timeStart = p_timeStart;
var p_timeComplete = p_timeComplete;
var removed:Boolean;
var tl:uint = _tweenList.length;
i = 0;
while (i < tl) {
if (((Boolean(_tweenList[i])) && ((p_scope == _tweenList[i].scope)))){
if ((((p_timeComplete > _tweenList[i].timeStart)) && ((p_timeStart < _tweenList[i].timeComplete)))){
removedLocally = false;
for (pName in _tweenList[i].properties) {
if (Boolean(p_properties[pName])){
if (Boolean(_tweenList[i].onOverwrite)){
eventScope = (Boolean(_tweenList[i].onOverwriteScope)) ? _tweenList[i].onOverwriteScope : _tweenList[i].scope;
_tweenList[i].onOverwrite.apply(eventScope, _tweenList[i].onOverwriteParams);
//unresolved jump
var _slot1 = e;
handleError(_tweenList[i], _slot1, "onOverwrite");
};
_tweenList[i].properties[pName] = undefined;
delete _tweenList[i].properties[pName];
removedLocally = true;
removed = true;
};
};
if (removedLocally){
if (AuxFunctions.getObjectLength(_tweenList[i].properties) == 0){
removeTweenByIndex(i);
};
};
};
};
i = (i + 1);
};
return (removed);
}
public static function registerSpecialPropertySplitter(p_name:String, p_splitFunction:Function, p_parameters:Array=null):void{
if (!_inited){
init();
};
var sps:SpecialPropertySplitter = new SpecialPropertySplitter(p_splitFunction, p_parameters);
_specialPropertySplitterList[p_name] = sps;
}
public static function removeTweenByIndex(i:Number, p_finalRemoval:Boolean=false):Boolean{
_tweenList[i] = null;
if (p_finalRemoval){
_tweenList.splice(i, 1);
};
return (true);
}
public static function resumeTweens(p_scope:Object, ... _args):Boolean{
var i:uint;
var properties:Array = new Array();
i = 0;
while (i < _args.length) {
if ((((typeof(_args[i]) == "string")) && (!(AuxFunctions.isInArray(_args[i], properties))))){
properties.push(_args[i]);
};
i++;
};
return (affectTweens(resumeTweenByIndex, p_scope, properties));
}
public static function pauseTweens(p_scope:Object, ... _args):Boolean{
var i:uint;
var properties:Array = new Array();
i = 0;
while (i < _args.length) {
if ((((typeof(_args[i]) == "string")) && (!(AuxFunctions.isInArray(_args[i], properties))))){
properties.push(_args[i]);
};
i++;
};
return (affectTweens(pauseTweenByIndex, p_scope, properties));
}
}
}//package caurina.transitions
Section 8
//TweenListObj (caurina.transitions.TweenListObj)
package caurina.transitions {
public class TweenListObj {
public var hasStarted:Boolean;
public var onUpdate:Function;
public var useFrames:Boolean;
public var count:Number;
public var onOverwriteParams:Array;
public var timeStart:Number;
public var timeComplete:Number;
public var onStartParams:Array;
public var onUpdateScope:Object;
public var rounded:Boolean;
public var onUpdateParams:Array;
public var properties:Object;
public var onComplete:Function;
public var transitionParams:Object;
public var updatesSkipped:Number;
public var onStart:Function;
public var onOverwriteScope:Object;
public var skipUpdates:Number;
public var onStartScope:Object;
public var scope:Object;
public var isCaller:Boolean;
public var timePaused:Number;
public var transition:Function;
public var onCompleteParams:Array;
public var onError:Function;
public var timesCalled:Number;
public var onErrorScope:Object;
public var onOverwrite:Function;
public var isPaused:Boolean;
public var waitFrames:Boolean;
public var onCompleteScope:Object;
public function TweenListObj(p_scope:Object, p_timeStart:Number, p_timeComplete:Number, p_useFrames:Boolean, p_transition:Function, p_transitionParams:Object){
super();
scope = p_scope;
timeStart = p_timeStart;
timeComplete = p_timeComplete;
useFrames = p_useFrames;
transition = p_transition;
transitionParams = p_transitionParams;
properties = new Object();
isPaused = false;
timePaused = undefined;
isCaller = false;
updatesSkipped = 0;
timesCalled = 0;
skipUpdates = 0;
hasStarted = false;
}
public function clone(omitEvents:Boolean):TweenListObj{
var pName:String;
var nTween:TweenListObj = new TweenListObj(scope, timeStart, timeComplete, useFrames, transition, transitionParams);
nTween.properties = new Array();
for (pName in properties) {
nTween.properties[pName] = properties[pName].clone();
};
nTween.skipUpdates = skipUpdates;
nTween.updatesSkipped = updatesSkipped;
if (!omitEvents){
nTween.onStart = onStart;
nTween.onUpdate = onUpdate;
nTween.onComplete = onComplete;
nTween.onOverwrite = onOverwrite;
nTween.onError = onError;
nTween.onStartParams = onStartParams;
nTween.onUpdateParams = onUpdateParams;
nTween.onCompleteParams = onCompleteParams;
nTween.onOverwriteParams = onOverwriteParams;
nTween.onStartScope = onStartScope;
nTween.onUpdateScope = onUpdateScope;
nTween.onCompleteScope = onCompleteScope;
nTween.onOverwriteScope = onOverwriteScope;
nTween.onErrorScope = onErrorScope;
};
nTween.rounded = rounded;
nTween.isPaused = isPaused;
nTween.timePaused = timePaused;
nTween.isCaller = isCaller;
nTween.count = count;
nTween.timesCalled = timesCalled;
nTween.waitFrames = waitFrames;
nTween.hasStarted = hasStarted;
return (nTween);
}
public function toString():String{
var i:String;
var returnStr:String = "\n[TweenListObj ";
returnStr = (returnStr + ("scope:" + String(scope)));
returnStr = (returnStr + ", properties:");
var isFirst:Boolean;
for (i in properties) {
if (!isFirst){
returnStr = (returnStr + ",");
};
returnStr = (returnStr + ("[name:" + properties[i].name));
returnStr = (returnStr + (",valueStart:" + properties[i].valueStart));
returnStr = (returnStr + (",valueComplete:" + properties[i].valueComplete));
returnStr = (returnStr + "]");
isFirst = false;
};
returnStr = (returnStr + (", timeStart:" + String(timeStart)));
returnStr = (returnStr + (", timeComplete:" + String(timeComplete)));
returnStr = (returnStr + (", useFrames:" + String(useFrames)));
returnStr = (returnStr + (", transition:" + String(transition)));
returnStr = (returnStr + (", transitionParams:" + String(transitionParams)));
if (skipUpdates){
returnStr = (returnStr + (", skipUpdates:" + String(skipUpdates)));
};
if (updatesSkipped){
returnStr = (returnStr + (", updatesSkipped:" + String(updatesSkipped)));
};
if (Boolean(onStart)){
returnStr = (returnStr + (", onStart:" + String(onStart)));
};
if (Boolean(onUpdate)){
returnStr = (returnStr + (", onUpdate:" + String(onUpdate)));
};
if (Boolean(onComplete)){
returnStr = (returnStr + (", onComplete:" + String(onComplete)));
};
if (Boolean(onOverwrite)){
returnStr = (returnStr + (", onOverwrite:" + String(onOverwrite)));
};
if (Boolean(onError)){
returnStr = (returnStr + (", onError:" + String(onError)));
};
if (onStartParams){
returnStr = (returnStr + (", onStartParams:" + String(onStartParams)));
};
if (onUpdateParams){
returnStr = (returnStr + (", onUpdateParams:" + String(onUpdateParams)));
};
if (onCompleteParams){
returnStr = (returnStr + (", onCompleteParams:" + String(onCompleteParams)));
};
if (onOverwriteParams){
returnStr = (returnStr + (", onOverwriteParams:" + String(onOverwriteParams)));
};
if (onStartScope){
returnStr = (returnStr + (", onStartScope:" + String(onStartScope)));
};
if (onUpdateScope){
returnStr = (returnStr + (", onUpdateScope:" + String(onUpdateScope)));
};
if (onCompleteScope){
returnStr = (returnStr + (", onCompleteScope:" + String(onCompleteScope)));
};
if (onOverwriteScope){
returnStr = (returnStr + (", onOverwriteScope:" + String(onOverwriteScope)));
};
if (onErrorScope){
returnStr = (returnStr + (", onErrorScope:" + String(onErrorScope)));
};
if (rounded){
returnStr = (returnStr + (", rounded:" + String(rounded)));
};
if (isPaused){
returnStr = (returnStr + (", isPaused:" + String(isPaused)));
};
if (timePaused){
returnStr = (returnStr + (", timePaused:" + String(timePaused)));
};
if (isCaller){
returnStr = (returnStr + (", isCaller:" + String(isCaller)));
};
if (count){
returnStr = (returnStr + (", count:" + String(count)));
};
if (timesCalled){
returnStr = (returnStr + (", timesCalled:" + String(timesCalled)));
};
if (waitFrames){
returnStr = (returnStr + (", waitFrames:" + String(waitFrames)));
};
if (hasStarted){
returnStr = (returnStr + (", hasStarted:" + String(hasStarted)));
};
returnStr = (returnStr + "]\n");
return (returnStr);
}
public static function makePropertiesChain(p_obj:Object):Object{
var chainedObject:Object;
var chain:Object;
var currChainObj:Object;
var len:Number;
var i:Number;
var k:Number;
var baseObject:Object = p_obj.base;
if (baseObject){
chainedObject = {};
if ((baseObject is Array)){
chain = [];
k = 0;
while (k < baseObject.length) {
chain.push(baseObject[k]);
k++;
};
} else {
chain = [baseObject];
};
chain.push(p_obj);
len = chain.length;
i = 0;
while (i < len) {
if (chain[i]["base"]){
currChainObj = AuxFunctions.concatObjects(makePropertiesChain(chain[i]["base"]), chain[i]);
} else {
currChainObj = chain[i];
};
chainedObject = AuxFunctions.concatObjects(chainedObject, currChainObj);
i++;
};
if (chainedObject["base"]){
delete chainedObject["base"];
};
return (chainedObject);
//unresolved jump
};
return (p_obj);
}
}
}//package caurina.transitions
Section 9
//GameEvent (com.greenish.onlinegames.events.GameEvent)
package com.greenish.onlinegames.events {
import flash.events.*;
public class GameEvent extends Event {
public var score:Number;
public var time:Number;
public static var TIMEOUT:String = "onTimeOut";
public static var GAMEOVER:String = "onGameOver";
public static var RETRY:String = "onRetry";
public static var THEEND:String = "onTheEnd";
public static var MAINMENU:String = "onMainMenu";
public function GameEvent(type:String, score:Number=0, time:Number=0){
super(type);
this.score = score;
this.time = time;
}
override public function toString():String{
return (formatToString("GameEvent", "type", "bubbles", "cancelable", "eventPhase"));
}
override public function clone():Event{
return (new GameEvent(type));
}
}
}//package com.greenish.onlinegames.events
Section 10
//GameOverClass (com.greenish.onlinegames.GameOverClass)
package com.greenish.onlinegames {
import flash.events.*;
import com.greenish.onlinegames.events.*;
import flash.utils.*;
import com.hurlant.crypto.symmetric.*;
import com.hurlant.crypto.*;
import com.hurlant.util.*;
import flash.net.*;
public class GameOverClass extends EventDispatcher {
private var output:String;
private var type:String;
private var time:Number;
private var score:Number;
private var currentResult:ByteArray;
public function GameOverClass(score:Number, time:Number, type:String){
var s:String;
var t:Timer;
super();
this.score = score;
this.time = time;
this.type = type;
if (MainClass.isOnOurServer){
s = ((((((((MainClass.idGame.toString() + ",") + MainClass.login) + ",") + MainClass.country.toString()) + ",") + score.toString()) + ",") + time.toString());
trace(s);
onLoadKey(Hex.fromArray(encrypt(s)));
} else {
t = new Timer(500, 1);
t.addEventListener(TimerEvent.TIMER, onLoadData);
t.start();
};
}
private function encrypt(str:String):ByteArray{
var kdata:ByteArray;
var data:ByteArray;
var iv:String;
var ivmode:IVMode;
var k:String = MainClass.skey;
var kformat:String = String("hex");
kdata = Hex.toArray(k);
var txt:String = str;
var format:String = String("text");
data = Hex.toArray(Hex.fromString(txt));
var name:String = "rc4";
var pad:IPad = new NullPad();
var mode:ICipher = Crypto.getCipher(name, kdata, pad);
pad.setBlockSize(mode.getBlockSize());
mode.encrypt(data);
currentResult = data;
if ((mode is IVMode)){
ivmode = (mode as IVMode);
iv = Hex.fromArray(ivmode.IV);
};
output = Hex.fromArray(currentResult);
return (currentResult);
}
private function onLoadData(e):void{
dispatchEvent(new GameEvent(type, score, time));
}
private function onLoadKey(s:String):void{
var myData1:URLRequest = new URLRequest(MainClass.scorePath);
myData1.method = URLRequestMethod.POST;
var variables1:URLVariables = new URLVariables();
variables1.str_out = s;
trace(("S = " + s));
myData1.data = variables1;
var loader1:URLLoader = new URLLoader();
loader1.dataFormat = URLLoaderDataFormat.VARIABLES;
loader1.addEventListener(Event.COMPLETE, onLoadData);
loader1.load(myData1);
}
}
}//package com.greenish.onlinegames
Section 11
//MainClass (com.greenish.onlinegames.MainClass)
package com.greenish.onlinegames {
import flash.events.*;
import com.greenish.onlinegames.events.*;
import flash.display.*;
import flash.system.*;
import flash.net.*;
public class MainClass extends MovieClip {
public static var server:String = "";
public static var keyPath:String = "";
public static var isOnOurServer:Boolean = true;
public static var login:String = "";
public static var skey:String = "";
public static var idGame:int = 0;
public static var country:int = 0;
public static var scorePath:String = "";
public function MainClass():void{
super();
if (stage){
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
};
}
public function init(e:Event=null):void{
Security.allowDomain("www.monsterz.ru");
Security.allowDomain("monsterz.ru");
Security.allowDomain("www.onlinegamestars.com");
Security.allowDomain("onlinegamestars.com");
Security.allowDomain("www.mygame.com");
removeEventListener(Event.ADDED_TO_STAGE, init);
login = LoaderInfo(this.root.loaderInfo).parameters.login;
keyPath = LoaderInfo(this.root.loaderInfo).parameters.keyPath;
scorePath = LoaderInfo(this.root.loaderInfo).parameters.scorePath;
country = int(LoaderInfo(this.root.loaderInfo).parameters.country);
idGame = int(LoaderInfo(this.root.loaderInfo).parameters.idGame);
server = LoaderInfo(this.root.loaderInfo).parameters.server;
trace("server", server);
if (server == null){
isOnOurServer = false;
server = "http://onlinegamestars.com/uplfile/xmlfiles/";
} else {
isOnOurServer = true;
};
trace("version 1.3", isOnOurServer, server);
if (isOnOurServer){
getKey(((((login + ",") + country.toString()) + ",") + idGame.toString()));
} else {
showRules();
};
}
public function showRules():void{
}
public function removeRules():void{
}
public function onLoadError(e:IOErrorEvent):void{
showError();
}
public function startGameClick(e:MouseEvent):void{
e.target.removeEventListener(MouseEvent.CLICK, startGame);
removeRules();
startGame();
}
public function setGameOver(e:GameEvent):void{
var goClass:GameOverClass = new GameOverClass(e.score, e.time, e.type);
goClass.addEventListener(GameEvent.THEEND, onShowEndPage);
goClass.addEventListener(GameEvent.GAMEOVER, onShowEndPage);
goClass.addEventListener(GameEvent.TIMEOUT, onShowEndPage);
}
private function getKey(s:String):void{
var myData:URLRequest = new URLRequest(keyPath);
myData.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.str_out = s;
myData.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
loader.load(myData);
}
public function showError():void{
var error:ErrorGfx = new ErrorGfx();
addChild(error);
}
public function startGame():void{
}
public function onShowEndPage(e:GameEvent):void{
}
private function dataOnLoad(e:Event):void{
skey = String(e.target.data.req);
trace(skey);
if (skey != ""){
showRules();
} else {
showError();
};
}
}
}//package com.greenish.onlinegames
Section 12
//Preloader (com.greenish.onlinegames.Preloader)
package com.greenish.onlinegames {
import flash.events.*;
import flash.display.*;
import flash.system.*;
import flash.net.*;
import flash.utils.*;
public class Preloader extends MovieClip {
private var game:DisplayObject;
public var csLoader:Loader;
private var progressBar:MovieClip;
public var isMustMochi:Boolean;// = false
public var candystand;
private var maska:Sprite;
public var gfx:PreloaderGfx;
public static var mochiId:String;
public function Preloader(){
super();
Security.allowDomain("www.candystand.com");
var candystandAPIURL:String = ((LoaderInfo(root.loaderInfo).parameters.apiurl) || ("http://www.candystand.com/api/flash/cs_api_3.0.swf"));
csLoader = new Loader();
csLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCandystandAPILoadComplete);
csLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onCandystandAPILoadError);
csLoader.load(new URLRequest(candystandAPIURL));
this.addChild(csLoader);
}
private function checkFrame(e:Event):void{
if (currentFrame == totalFrames){
removeEventListener(Event.ENTER_FRAME, checkFrame);
startup();
};
}
public function onStingerComplete(e):void{
stage.scaleMode = StageScaleMode.SHOW_ALL;
stage.align = StageAlign.TOP_LEFT;
gfx = new PreloaderGfx();
progressBar = (gfx["progress"] as MovieClip);
progressBar.scaleX = 0;
gfx.x = 0;
gfx.y = 0;
addChild(gfx);
addEventListener(Event.ENTER_FRAME, checkFrame);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
}
public function onCandystandAPILoadComplete(e:Event):void{
candystand = e.target.content;
candystand.init("Jpf98nk89o", "1.0.0");
candystand.loadStinger();
candystand.stinger.addEventListener("STINGER_COMPLETE", this.onStingerComplete);
}
public function progress(e:ProgressEvent):void{
progressBar.scaleX = (e.bytesLoaded / e.bytesTotal);
}
public function onCandystandAPILoadError(e:Event):void{
trace(("ERROR LOADING CANDYSTAND API: " + e));
}
public function startGame():void{
maska = new Sprite();
maska.graphics.beginFill(0, 0.5);
maska.graphics.lineStyle(1, 0, 1);
maska.graphics.drawRect(0, 0, 776, 576);
maska.graphics.endFill();
var content:Sprite = new Sprite();
addChild(content);
addChild(maska);
content.mask = maska;
var mainClass:Class = (getDefinitionByName("Main") as Class);
game = (new mainClass(candystand) as DisplayObject);
content.addChild(game);
}
public function startup():void{
stop();
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
removeChild(gfx);
startGame();
}
private function onStartMochi(e:Event):void{
startGame();
}
}
}//package com.greenish.onlinegames
Section 13
//HMAC (com.hurlant.crypto.hash.HMAC)
package com.hurlant.crypto.hash {
import flash.utils.*;
public class HMAC {
private var bits:uint;
private var hash:IHash;
public function HMAC(hash:IHash, bits:uint=0){
super();
this.hash = hash;
this.bits = bits;
}
public function getHashSize():uint{
if (bits != 0){
return ((bits / 8));
};
return (hash.getHashSize());
}
public function dispose():void{
hash = null;
bits = 0;
}
public function compute(key:ByteArray, data:ByteArray):ByteArray{
var hashKey:ByteArray;
var innerKey:ByteArray;
var outerKey:ByteArray;
var i:uint;
var innerHash:ByteArray;
var outerHash:ByteArray;
if (key.length > hash.getInputSize()){
hashKey = hash.hash(key);
} else {
hashKey = new ByteArray();
hashKey.writeBytes(key);
};
while (hashKey.length < hash.getInputSize()) {
hashKey[hashKey.length] = 0;
};
innerKey = new ByteArray();
outerKey = new ByteArray();
i = 0;
while (i < hashKey.length) {
innerKey[i] = (hashKey[i] ^ 54);
outerKey[i] = (hashKey[i] ^ 92);
i++;
};
innerKey.position = hashKey.length;
innerKey.writeBytes(data);
innerHash = hash.hash(innerKey);
outerKey.position = hashKey.length;
outerKey.writeBytes(innerHash);
outerHash = hash.hash(outerKey);
if ((((bits > 0)) && ((bits < (8 * outerHash.length))))){
outerHash.length = (bits / 8);
};
return (outerHash);
}
public function toString():String{
return ((("hmac-" + ((bits > 0)) ? (bits + "-") : "") + hash.toString()));
}
}
}//package com.hurlant.crypto.hash
Section 14
//IHash (com.hurlant.crypto.hash.IHash)
package com.hurlant.crypto.hash {
import flash.utils.*;
public interface IHash {
function toString():String;
function getHashSize():uint;
function getInputSize():uint;
function hash(C:\ws\Crypto;com\hurlant\crypto\hash;IHash.as:ByteArray):ByteArray;
}
}//package com.hurlant.crypto.hash
Section 15
//MD2 (com.hurlant.crypto.hash.MD2)
package com.hurlant.crypto.hash {
import flash.utils.*;
public class MD2 implements IHash {
public static const HASH_SIZE:int = 16;
private static const S:Array = [41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251, 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63, 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50, 39, 53, 62, 204, 231, 191, 247, 151, 3, 0xFF, 25, 48, 179, 72, 165, 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210, 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157, 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27, 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233, 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228, 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20];
public function MD2(){
super();
}
public function getHashSize():uint{
return (HASH_SIZE);
}
public function toString():String{
return ("md2");
}
public function getInputSize():uint{
return (16);
}
public function hash(src:ByteArray):ByteArray{
var savedLength:uint;
var i:uint;
var len:uint;
var checksum:ByteArray;
var L:uint;
var X:ByteArray;
var j:uint;
var t:uint;
var k:uint;
savedLength = src.length;
i = (((16 - (src.length % 16))) || (16));
do {
src[src.length] = i;
} while ((src.length % 16) != 0);
len = src.length;
checksum = new ByteArray();
L = 0;
i = 0;
while (i < len) {
j = 0;
while (j < 16) {
L = (checksum[j] = (checksum[j] ^ S[(src[(i + j)] ^ L)]));
j++;
};
i = (i + 16);
};
src.position = src.length;
src.writeBytes(checksum);
len = (len + 16);
X = new ByteArray();
i = 0;
while (i < len) {
j = 0;
while (j < 16) {
X[(32 + j)] = ((X[(16 + j)] = src[(i + j)]) ^ X[j]);
j++;
};
t = 0;
j = 0;
while (j < 18) {
k = 0;
while (k < 48) {
t = (X[k] ^ S[t]);
X[k] = t;
k++;
};
t = ((t + j) & 0xFF);
j++;
};
i = (i + 16);
};
X.length = 16;
src.length = savedLength;
return (X);
}
}
}//package com.hurlant.crypto.hash
Section 16
//MD5 (com.hurlant.crypto.hash.MD5)
package com.hurlant.crypto.hash {
import flash.utils.*;
public class MD5 implements IHash {
public static const HASH_SIZE:int = 16;
public function MD5(){
super();
}
private function ff(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint{
return (cmn(((b & c) | (~(b) & d)), a, b, x, s, t));
}
private function hh(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint{
return (cmn(((b ^ c) ^ d), a, b, x, s, t));
}
private function cmn(q:uint, a:uint, b:uint, x:uint, s:uint, t:uint):uint{
return ((rol((((a + q) + x) + t), s) + b));
}
public function getHashSize():uint{
return (HASH_SIZE);
}
private function ii(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint{
return (cmn((c ^ (b | ~(d))), a, b, x, s, t));
}
private function rol(num:uint, cnt:uint):uint{
return (((num << cnt) | (num >>> (32 - cnt))));
}
public function toString():String{
return ("md5");
}
public function getInputSize():uint{
return (64);
}
private function gg(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint{
return (cmn(((b & d) | (c & ~(d))), a, b, x, s, t));
}
public function hash(src:ByteArray):ByteArray{
var len:uint;
var savedEndian:String;
var a:Array;
var i:uint;
var h:Array;
var out:ByteArray;
len = (src.length * 8);
savedEndian = src.endian;
while ((src.length % 4) != 0) {
src[src.length] = 0;
};
src.position = 0;
a = [];
src.endian = Endian.LITTLE_ENDIAN;
i = 0;
while (i < src.length) {
a.push(src.readUnsignedInt());
i = (i + 4);
};
h = core_md5(a, len);
out = new ByteArray();
out.endian = Endian.LITTLE_ENDIAN;
i = 0;
while (i < 4) {
out.writeUnsignedInt(h[i]);
i++;
};
src.length = (len / 8);
src.endian = savedEndian;
return (out);
}
private function core_md5(x:Array, len:uint):Array{
var a:uint;
var b:uint;
var c:uint;
var d:uint;
var i:uint;
var olda:uint;
var oldb:uint;
var oldc:uint;
var oldd:uint;
x[(len >> 5)] = (x[(len >> 5)] | (128 << (len % 32)));
x[((((len + 64) >>> 9) << 4) + 14)] = len;
a = 1732584193;
b = 4023233417;
c = 2562383102;
d = 271733878;
i = 0;
while (i < x.length) {
x[i] = ((x[i]) || (0));
x[(i + 1)] = ((x[(i + 1)]) || (0));
x[(i + 2)] = ((x[(i + 2)]) || (0));
x[(i + 3)] = ((x[(i + 3)]) || (0));
x[(i + 4)] = ((x[(i + 4)]) || (0));
x[(i + 5)] = ((x[(i + 5)]) || (0));
x[(i + 6)] = ((x[(i + 6)]) || (0));
x[(i + 7)] = ((x[(i + 7)]) || (0));
x[(i + 8)] = ((x[(i + 8)]) || (0));
x[(i + 9)] = ((x[(i + 9)]) || (0));
x[(i + 10)] = ((x[(i + 10)]) || (0));
x[(i + 11)] = ((x[(i + 11)]) || (0));
x[(i + 12)] = ((x[(i + 12)]) || (0));
x[(i + 13)] = ((x[(i + 13)]) || (0));
x[(i + 14)] = ((x[(i + 14)]) || (0));
x[(i + 15)] = ((x[(i + 15)]) || (0));
olda = a;
oldb = b;
oldc = c;
oldd = d;
a = ff(a, b, c, d, x[(i + 0)], 7, 3614090360);
d = ff(d, a, b, c, x[(i + 1)], 12, 3905402710);
c = ff(c, d, a, b, x[(i + 2)], 17, 606105819);
b = ff(b, c, d, a, x[(i + 3)], 22, 3250441966);
a = ff(a, b, c, d, x[(i + 4)], 7, 4118548399);
d = ff(d, a, b, c, x[(i + 5)], 12, 1200080426);
c = ff(c, d, a, b, x[(i + 6)], 17, 2821735955);
b = ff(b, c, d, a, x[(i + 7)], 22, 4249261313);
a = ff(a, b, c, d, x[(i + 8)], 7, 1770035416);
d = ff(d, a, b, c, x[(i + 9)], 12, 2336552879);
c = ff(c, d, a, b, x[(i + 10)], 17, 4294925233);
b = ff(b, c, d, a, x[(i + 11)], 22, 2304563134);
a = ff(a, b, c, d, x[(i + 12)], 7, 1804603682);
d = ff(d, a, b, c, x[(i + 13)], 12, 4254626195);
c = ff(c, d, a, b, x[(i + 14)], 17, 2792965006);
b = ff(b, c, d, a, x[(i + 15)], 22, 1236535329);
a = gg(a, b, c, d, x[(i + 1)], 5, 4129170786);
d = gg(d, a, b, c, x[(i + 6)], 9, 3225465664);
c = gg(c, d, a, b, x[(i + 11)], 14, 643717713);
b = gg(b, c, d, a, x[(i + 0)], 20, 3921069994);
a = gg(a, b, c, d, x[(i + 5)], 5, 3593408605);
d = gg(d, a, b, c, x[(i + 10)], 9, 38016083);
c = gg(c, d, a, b, x[(i + 15)], 14, 3634488961);
b = gg(b, c, d, a, x[(i + 4)], 20, 3889429448);
a = gg(a, b, c, d, x[(i + 9)], 5, 568446438);
d = gg(d, a, b, c, x[(i + 14)], 9, 3275163606);
c = gg(c, d, a, b, x[(i + 3)], 14, 4107603335);
b = gg(b, c, d, a, x[(i + 8)], 20, 1163531501);
a = gg(a, b, c, d, x[(i + 13)], 5, 2850285829);
d = gg(d, a, b, c, x[(i + 2)], 9, 4243563512);
c = gg(c, d, a, b, x[(i + 7)], 14, 1735328473);
b = gg(b, c, d, a, x[(i + 12)], 20, 2368359562);
a = hh(a, b, c, d, x[(i + 5)], 4, 4294588738);
d = hh(d, a, b, c, x[(i + 8)], 11, 2272392833);
c = hh(c, d, a, b, x[(i + 11)], 16, 1839030562);
b = hh(b, c, d, a, x[(i + 14)], 23, 4259657740);
a = hh(a, b, c, d, x[(i + 1)], 4, 2763975236);
d = hh(d, a, b, c, x[(i + 4)], 11, 1272893353);
c = hh(c, d, a, b, x[(i + 7)], 16, 4139469664);
b = hh(b, c, d, a, x[(i + 10)], 23, 3200236656);
a = hh(a, b, c, d, x[(i + 13)], 4, 681279174);
d = hh(d, a, b, c, x[(i + 0)], 11, 3936430074);
c = hh(c, d, a, b, x[(i + 3)], 16, 3572445317);
b = hh(b, c, d, a, x[(i + 6)], 23, 76029189);
a = hh(a, b, c, d, x[(i + 9)], 4, 3654602809);
d = hh(d, a, b, c, x[(i + 12)], 11, 3873151461);
c = hh(c, d, a, b, x[(i + 15)], 16, 530742520);
b = hh(b, c, d, a, x[(i + 2)], 23, 3299628645);
a = ii(a, b, c, d, x[(i + 0)], 6, 4096336452);
d = ii(d, a, b, c, x[(i + 7)], 10, 1126891415);
c = ii(c, d, a, b, x[(i + 14)], 15, 2878612391);
b = ii(b, c, d, a, x[(i + 5)], 21, 4237533241);
a = ii(a, b, c, d, x[(i + 12)], 6, 1700485571);
d = ii(d, a, b, c, x[(i + 3)], 10, 2399980690);
c = ii(c, d, a, b, x[(i + 10)], 15, 4293915773);
b = ii(b, c, d, a, x[(i + 1)], 21, 2240044497);
a = ii(a, b, c, d, x[(i + 8)], 6, 1873313359);
d = ii(d, a, b, c, x[(i + 15)], 10, 4264355552);
c = ii(c, d, a, b, x[(i + 6)], 15, 2734768916);
b = ii(b, c, d, a, x[(i + 13)], 21, 1309151649);
a = ii(a, b, c, d, x[(i + 4)], 6, 4149444226);
d = ii(d, a, b, c, x[(i + 11)], 10, 3174756917);
c = ii(c, d, a, b, x[(i + 2)], 15, 718787259);
b = ii(b, c, d, a, x[(i + 9)], 21, 3951481745);
a = (a + olda);
b = (b + oldb);
c = (c + oldc);
d = (d + oldd);
i = (i + 16);
};
return ([a, b, c, d]);
}
}
}//package com.hurlant.crypto.hash
Section 17
//SHA1 (com.hurlant.crypto.hash.SHA1)
package com.hurlant.crypto.hash {
public class SHA1 extends SHABase implements IHash {
public static const HASH_SIZE:int = 20;
public function SHA1(){
super();
}
private function ft(t:uint, b:uint, c:uint, d:uint):uint{
if (t < 20){
return (((b & c) | (~(b) & d)));
};
if (t < 40){
return (((b ^ c) ^ d));
};
if (t < 60){
return ((((b & c) | (b & d)) | (c & d)));
};
return (((b ^ c) ^ d));
}
private function kt(t:uint):uint{
return (((t)<20) ? 1518500249 : ((t)<40) ? 1859775393 : ((t)<60) ? 2400959708 : 3395469782);
}
override public function toString():String{
return ("sha1");
}
override public function getHashSize():uint{
return (HASH_SIZE);
}
private function rol(num:uint, cnt:uint):uint{
return (((num << cnt) | (num >>> (32 - cnt))));
}
override protected function core(x:Array, len:uint):Array{
var w:Array;
var a:uint;
var b:uint;
var c:uint;
var d:uint;
var e:uint;
var i:uint;
var olda:uint;
var oldb:uint;
var oldc:uint;
var oldd:uint;
var olde:uint;
var j:uint;
var t:uint;
x[(len >> 5)] = (x[(len >> 5)] | (128 << (24 - (len % 32))));
x[((((len + 64) >> 9) << 4) + 15)] = len;
w = [];
a = 1732584193;
b = 4023233417;
c = 2562383102;
d = 271733878;
e = 3285377520;
i = 0;
while (i < x.length) {
olda = a;
oldb = b;
oldc = c;
oldd = d;
olde = e;
j = 0;
while (j < 80) {
if (j < 16){
w[j] = ((x[(i + j)]) || (0));
} else {
w[j] = rol((((w[(j - 3)] ^ w[(j - 8)]) ^ w[(j - 14)]) ^ w[(j - 16)]), 1);
};
t = ((((rol(a, 5) + ft(j, b, c, d)) + e) + w[j]) + kt(j));
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
j++;
};
a = (a + olda);
b = (b + oldb);
c = (c + oldc);
d = (d + oldd);
e = (e + olde);
i = (i + 16);
};
return ([a, b, c, d, e]);
}
}
}//package com.hurlant.crypto.hash
Section 18
//SHA224 (com.hurlant.crypto.hash.SHA224)
package com.hurlant.crypto.hash {
public class SHA224 extends SHA256 {
public function SHA224(){
super();
h = [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428];
}
override public function getHashSize():uint{
return (28);
}
override public function toString():String{
return ("sha224");
}
}
}//package com.hurlant.crypto.hash
Section 19
//SHA256 (com.hurlant.crypto.hash.SHA256)
package com.hurlant.crypto.hash {
public class SHA256 extends SHABase implements IHash {
protected var h:Array;
protected static const k:Array = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298];
public function SHA256(){
h = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225];
super();
}
protected function rrol(num:uint, cnt:uint):uint{
return (((num << (32 - cnt)) | (num >>> cnt)));
}
override public function toString():String{
return ("sha256");
}
override public function getHashSize():uint{
return (32);
}
override protected function core(x:Array, len:uint):Array{
var w:Array;
var a:uint;
var b:uint;
var c:uint;
var d:uint;
var e:uint;
var f:uint;
var g:uint;
var h:uint;
var i:uint;
var olda:uint;
var oldb:uint;
var oldc:uint;
var oldd:uint;
var olde:uint;
var oldf:uint;
var oldg:uint;
var oldh:uint;
var j:uint;
var t2:uint;
var t1:uint;
var s0:uint;
var s1:uint;
x[(len >> 5)] = (x[(len >> 5)] | (128 << (24 - (len % 32))));
x[((((len + 64) >> 9) << 4) + 15)] = len;
w = [];
a = h[0];
b = h[1];
c = h[2];
d = h[3];
e = h[4];
f = h[5];
g = h[6];
h = h[7];
i = 0;
while (i < x.length) {
olda = a;
oldb = b;
oldc = c;
oldd = d;
olde = e;
oldf = f;
oldg = g;
oldh = h;
j = 0;
while (j < 64) {
if (j < 16){
w[j] = ((x[(i + j)]) || (0));
} else {
s0 = ((rrol(w[(j - 15)], 7) ^ rrol(w[(j - 15)], 18)) ^ (w[(j - 15)] >>> 3));
s1 = ((rrol(w[(j - 2)], 17) ^ rrol(w[(j - 2)], 19)) ^ (w[(j - 2)] >>> 10));
w[j] = (((w[(j - 16)] + s0) + w[(j - 7)]) + s1);
};
t2 = (((rrol(a, 2) ^ rrol(a, 13)) ^ rrol(a, 22)) + (((a & b) ^ (a & c)) ^ (b & c)));
t1 = ((((h + ((rrol(e, 6) ^ rrol(e, 11)) ^ rrol(e, 25))) + ((e & f) ^ (g & ~(e)))) + k[j]) + w[j]);
h = g;
g = f;
f = e;
e = (d + t1);
d = c;
c = b;
b = a;
a = (t1 + t2);
j++;
};
a = (a + olda);
b = (b + oldb);
c = (c + oldc);
d = (d + oldd);
e = (e + olde);
f = (f + oldf);
g = (g + oldg);
h = (h + oldh);
i = (i + 16);
};
return ([a, b, c, d, e, f, g, h]);
}
}
}//package com.hurlant.crypto.hash
Section 20
//SHABase (com.hurlant.crypto.hash.SHABase)
package com.hurlant.crypto.hash {
import flash.utils.*;
public class SHABase implements IHash {
public function SHABase(){
super();
}
public function getHashSize():uint{
return (0);
}
public function toString():String{
return ("sha");
}
public function getInputSize():uint{
return (64);
}
public function hash(src:ByteArray):ByteArray{
var savedLength:uint;
var savedEndian:String;
var len:uint;
var a:Array;
var i:uint;
var h:Array;
var out:ByteArray;
var words:uint;
savedLength = src.length;
savedEndian = src.endian;
src.endian = Endian.BIG_ENDIAN;
len = (savedLength * 8);
while ((src.length % 4) != 0) {
src[src.length] = 0;
};
src.position = 0;
a = [];
i = 0;
while (i < src.length) {
a.push(src.readUnsignedInt());
i = (i + 4);
};
h = core(a, len);
out = new ByteArray();
words = (getHashSize() / 4);
i = 0;
while (i < words) {
out.writeUnsignedInt(h[i]);
i++;
};
src.length = savedLength;
src.endian = savedEndian;
return (out);
}
protected function core(x:Array, len:uint):Array{
return (null);
}
}
}//package com.hurlant.crypto.hash
Section 21
//ARC4 (com.hurlant.crypto.prng.ARC4)
package com.hurlant.crypto.prng {
import flash.utils.*;
import com.hurlant.crypto.symmetric.*;
import com.hurlant.util.*;
public class ARC4 implements IPRNG, IStreamCipher {
private const psize:uint = 0x0100;
private var S:ByteArray;
private var i:int;// = 0
private var j:int;// = 0
public function ARC4(key:ByteArray=null){
i = 0;
j = 0;
super();
S = new ByteArray();
if (key){
init(key);
};
}
public function decrypt(block:ByteArray):void{
encrypt(block);
}
public function init(key:ByteArray):void{
var i:int;
var j:int;
var t:int;
i = 0;
while (i < 0x0100) {
S[i] = i;
i++;
};
j = 0;
i = 0;
while (i < 0x0100) {
j = (((j + S[i]) + key[(i % key.length)]) & 0xFF);
t = S[i];
S[i] = S[j];
S[j] = t;
i++;
};
this.i = 0;
this.j = 0;
}
public function dispose():void{
var i:uint;
i = 0;
if (S != null){
i = 0;
while (i < S.length) {
S[i] = (Math.random() * 0x0100);
i++;
};
S.length = 0;
S = null;
};
this.i = 0;
this.j = 0;
Memory.gc();
}
public function encrypt(block:ByteArray):void{
var i:uint;
i = 0;
while (i < block.length) {
var _temp1 = i;
i = (i + 1);
var _local3 = _temp1;
block[_local3] = (block[_local3] ^ next());
};
}
public function next():uint{
var t:int;
i = ((i + 1) & 0xFF);
j = ((j + S[i]) & 0xFF);
t = S[i];
S[i] = S[j];
S[j] = t;
return (S[((t + S[i]) & 0xFF)]);
}
public function getBlockSize():uint{
return (1);
}
public function getPoolSize():uint{
return (psize);
}
public function toString():String{
return ("rc4");
}
}
}//package com.hurlant.crypto.prng
Section 22
//IPRNG (com.hurlant.crypto.prng.IPRNG)
package com.hurlant.crypto.prng {
import flash.utils.*;
public interface IPRNG {
function init(C:\ws\Crypto;com\hurlant\crypto\prng;IPRNG.as:ByteArray):void;
function next():uint;
function dispose():void;
function getPoolSize():uint;
function toString():String;
}
}//package com.hurlant.crypto.prng
Section 23
//Random (com.hurlant.crypto.prng.Random)
package com.hurlant.crypto.prng {
import flash.utils.*;
import flash.text.*;
import com.hurlant.util.*;
import flash.system.*;
public class Random {
private var psize:int;
private var ready:Boolean;// = false
private var seeded:Boolean;// = false
private var state:IPRNG;
private var pool:ByteArray;
private var pptr:int;
public function Random(prng:Class=null){
var t:uint;
ready = false;
seeded = false;
super();
if (prng == null){
prng = ARC4;
};
state = (new (prng) as IPRNG);
psize = state.getPoolSize();
pool = new ByteArray();
pptr = 0;
while (pptr < psize) {
t = (65536 * Math.random());
var _local3 = pptr++;
pool[_local3] = (t >>> 8);
var _local4 = pptr++;
pool[_local4] = (t & 0xFF);
};
pptr = 0;
seed();
}
public function seed(x:int=0):void{
if (x == 0){
x = new Date().getTime();
};
var _local2 = pptr++;
pool[_local2] = (pool[_local2] ^ (x & 0xFF));
var _local3 = pptr++;
pool[_local3] = (pool[_local3] ^ ((x >> 8) & 0xFF));
var _local4 = pptr++;
pool[_local4] = (pool[_local4] ^ ((x >> 16) & 0xFF));
var _local5 = pptr++;
pool[_local5] = (pool[_local5] ^ ((x >> 24) & 0xFF));
pptr = (pptr % psize);
seeded = true;
}
public function toString():String{
return (("random-" + state.toString()));
}
public function dispose():void{
var i:uint;
i = 0;
while (i < pool.length) {
pool[i] = (Math.random() * 0x0100);
i++;
};
pool.length = 0;
pool = null;
state.dispose();
state = null;
psize = 0;
pptr = 0;
Memory.gc();
}
public function autoSeed():void{
var b:ByteArray;
var a:Array;
var f:Font;
b = new ByteArray();
b.writeUnsignedInt(System.totalMemory);
b.writeUTF(Capabilities.serverString);
b.writeUnsignedInt(getTimer());
b.writeUnsignedInt(new Date().getTime());
a = Font.enumerateFonts(true);
for each (f in a) {
b.writeUTF(f.fontName);
b.writeUTF(f.fontStyle);
b.writeUTF(f.fontType);
};
b.position = 0;
while (b.bytesAvailable >= 4) {
seed(b.readUnsignedInt());
};
}
public function nextByte():int{
if (!ready){
if (!seeded){
autoSeed();
};
state.init(pool);
pool.length = 0;
pptr = 0;
ready = true;
};
return (state.next());
}
public function nextBytes(buffer:ByteArray, length:int):void{
while (length--) {
buffer.writeByte(nextByte());
};
}
}
}//package com.hurlant.crypto.prng
Section 24
//RSAKey (com.hurlant.crypto.rsa.RSAKey)
package com.hurlant.crypto.rsa {
import flash.utils.*;
import com.hurlant.math.*;
import com.hurlant.crypto.prng.*;
import com.hurlant.util.*;
public class RSAKey {
public var dmp1:BigInteger;
protected var canDecrypt:Boolean;
public var d:BigInteger;
public var e:int;
public var dmq1:BigInteger;
public var n:BigInteger;
public var p:BigInteger;
public var q:BigInteger;
protected var canEncrypt:Boolean;
public var coeff:BigInteger;
public function RSAKey(N:BigInteger, E:int, D:BigInteger=null, P:BigInteger=null, Q:BigInteger=null, DP:BigInteger=null, DQ:BigInteger=null, C:BigInteger=null){
super();
this.n = N;
this.e = E;
this.d = D;
this.p = P;
this.q = Q;
this.dmp1 = DP;
this.dmq1 = DQ;
this.coeff = C;
canEncrypt = ((!((n == null))) && (!((e == 0))));
canDecrypt = ((canEncrypt) && (!((d == null))));
}
public function verify(src:ByteArray, dst:ByteArray, length:uint, pad:Function=null):void{
_decrypt(doPublic, src, dst, length, pad, 1);
}
public function dump():String{
var s:String;
s = ((((("N=" + n.toString(16)) + "\n") + "E=") + e.toString(16)) + "\n");
if (canDecrypt){
s = (s + (("D=" + d.toString(16)) + "\n"));
if (((!((p == null))) && (!((q == null))))){
s = (s + (("P=" + p.toString(16)) + "\n"));
s = (s + (("Q=" + q.toString(16)) + "\n"));
s = (s + (("DMP1=" + dmp1.toString(16)) + "\n"));
s = (s + (("DMQ1=" + dmq1.toString(16)) + "\n"));
s = (s + (("IQMP=" + coeff.toString(16)) + "\n"));
};
};
return (s);
}
protected function doPrivate2(x:BigInteger):BigInteger{
var xp:BigInteger;
var xq:BigInteger;
var r:BigInteger;
if ((((p == null)) && ((q == null)))){
return (x.modPow(d, n));
};
xp = x.mod(p).modPow(dmp1, p);
xq = x.mod(q).modPow(dmq1, q);
while (xp.compareTo(xq) < 0) {
xp = xp.add(p);
};
r = xp.subtract(xq).multiply(coeff).mod(p).multiply(q).add(xq);
return (r);
}
public function decrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function=null):void{
_decrypt(doPrivate2, src, dst, length, pad, 2);
}
private function _decrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int):void{
var bl:uint;
var end:int;
var block:BigInteger;
var chunk:BigInteger;
var b:ByteArray;
if (pad == null){
pad = pkcs1unpad;
};
if (src.position >= src.length){
src.position = 0;
};
bl = getBlockSize();
end = (src.position + length);
while (src.position < end) {
block = new BigInteger(src, length);
chunk = op(block);
b = pad(chunk, bl);
dst.writeBytes(b);
};
}
protected function doPublic(x:BigInteger):BigInteger{
return (x.modPowInt(e, n));
}
public function dispose():void{
e = 0;
n.dispose();
n = null;
Memory.gc();
}
private function _encrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int):void{
var bl:uint;
var end:int;
var block:BigInteger;
var chunk:BigInteger;
if (pad == null){
pad = pkcs1pad;
};
if (src.position >= src.length){
src.position = 0;
};
bl = getBlockSize();
end = (src.position + length);
while (src.position < end) {
block = new BigInteger(pad(src, end, bl, padType), bl);
chunk = op(block);
chunk.toArray(dst);
};
}
private function rawpad(src:ByteArray, end:int, n:uint):ByteArray{
return (src);
}
public function encrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function=null):void{
_encrypt(doPublic, src, dst, length, pad, 2);
}
private function pkcs1pad(src:ByteArray, end:int, n:uint, type:uint=2):ByteArray{
var out:ByteArray;
var p:uint;
var i:int;
var rng:Random;
var x:int;
out = new ByteArray();
p = src.position;
end = Math.min(end, src.length, ((p + n) - 11));
src.position = end;
i = (end - 1);
while ((((i >= p)) && ((n > 11)))) {
--n;
var _local10 = n;
var _temp1 = i;
i = (i - 1);
out[_local10] = src[_temp1];
};
--n;
_local10 = n;
out[_local10] = 0;
rng = new Random();
while (n > 2) {
x = 0;
while (x == 0) {
x = ((type)==2) ? rng.nextByte() : 0xFF;
};
--n;
var _local11 = n;
out[_local11] = x;
};
--n;
_local11 = n;
out[_local11] = type;
--n;
var _local12 = n;
out[_local12] = 0;
return (out);
}
private function pkcs1unpad(src:BigInteger, n:uint, type:uint=2):ByteArray{
var b:ByteArray;
var out:ByteArray;
var i:int;
b = src.toByteArray();
out = new ByteArray();
i = 0;
while ((((i < b.length)) && ((b[i] == 0)))) {
i++;
};
if (((!(((b.length - i) == (n - 1)))) || ((b[i] > 2)))){
trace(((("PKCS#1 unpad: i=" + i) + ", expected b[i]==[0,1,2], got b[i]=") + b[i].toString(16)));
return (null);
};
i++;
while (b[i] != 0) {
++i;
if (i >= b.length){
trace((((("PKCS#1 unpad: i=" + i) + ", b[i-1]!=0 (=") + b[(i - 1)].toString(16)) + ")"));
return (null);
};
};
while (++i < b.length) {
out.writeByte(b[i]);
};
out.position = 0;
return (out);
}
public function getBlockSize():uint{
return (((n.bitLength() + 7) / 8));
}
public function toString():String{
return ("rsa");
}
public function sign(src:ByteArray, dst:ByteArray, length:uint, pad:Function=null):void{
_encrypt(doPrivate2, src, dst, length, pad, 1);
}
protected function doPrivate(x:BigInteger):BigInteger{
var xp:BigInteger;
var xq:BigInteger;
if ((((p == null)) || ((q == null)))){
return (x.modPow(d, n));
};
xp = x.mod(p).modPow(dmp1, p);
xq = x.mod(q).modPow(dmq1, q);
while (xp.compareTo(xq) < 0) {
xp = xp.add(p);
};
return (xp.subtract(xq).multiply(coeff).mod(p).multiply(q).add(xq));
}
protected static function bigRandom(bits:int, rnd:Random):BigInteger{
var x:ByteArray;
var b:BigInteger;
if (bits < 2){
return (BigInteger.nbv(1));
};
x = new ByteArray();
rnd.nextBytes(x, (bits >> 3));
x.position = 0;
b = new BigInteger(x);
b.primify(bits, 1);
return (b);
}
public static function parsePublicKey(N:String, E:String):RSAKey{
return (new RSAKey(new BigInteger(N, 16), parseInt(E, 16)));
}
public static function generate(B:uint, E:String):RSAKey{
var rng:Random;
var qs:uint;
var key:RSAKey;
var ee:BigInteger;
var p1:BigInteger;
var q1:BigInteger;
var phi:BigInteger;
var t:BigInteger;
rng = new Random();
qs = (B >> 1);
key = new RSAKey(null, 0, null);
key.e = parseInt(E, 16);
ee = new BigInteger(E, 16);
while (true) {
while (true) {
key.p = bigRandom((B - qs), rng);
if ((((key.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0)) && (key.p.isProbablePrime(10)))){
break;
};
};
while (true) {
key.q = bigRandom(qs, rng);
if ((((key.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0)) && (key.q.isProbablePrime(10)))){
break;
};
};
if (key.p.compareTo(key.q) <= 0){
t = key.p;
key.p = key.q;
key.q = t;
};
p1 = key.p.subtract(BigInteger.ONE);
q1 = key.q.subtract(BigInteger.ONE);
phi = p1.multiply(q1);
if (phi.gcd(ee).compareTo(BigInteger.ONE) == 0){
key.n = key.p.multiply(key.q);
key.d = ee.modInverse(phi);
key.dmp1 = key.d.mod(p1);
key.dmq1 = key.d.mod(q1);
key.coeff = key.q.modInverse(key.p);
break;
};
};
return (key);
}
public static function parsePrivateKey(N:String, E:String, D:String, P:String=null, Q:String=null, DMP1:String=null, DMQ1:String=null, IQMP:String=null):RSAKey{
if (P == null){
return (new RSAKey(new BigInteger(N, 16), parseInt(E, 16), new BigInteger(D, 16)));
};
return (new RSAKey(new BigInteger(N, 16), parseInt(E, 16), new BigInteger(D, 16), new BigInteger(P, 16), new BigInteger(Q, 16), new BigInteger(DMP1, 16), new BigInteger(DMQ1), new BigInteger(IQMP)));
}
}
}//package com.hurlant.crypto.rsa
Section 25
//AESKey (com.hurlant.crypto.symmetric.AESKey)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.crypto.prng.*;
import com.hurlant.util.*;
public class AESKey implements ISymmetricKey {
private var state:ByteArray;
private var tmp:ByteArray;
private var Nr:uint;
private var keyLength:uint;
private var key:ByteArray;
private static const _Xtime2:Array = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 27, 25, 31, 29, 19, 17, 23, 21, 11, 9, 15, 13, 3, 1, 7, 5, 59, 57, 63, 61, 51, 49, 55, 53, 43, 41, 47, 45, 35, 33, 39, 37, 91, 89, 95, 93, 83, 81, 87, 85, 75, 73, 79, 77, 67, 65, 71, 69, 123, 121, 127, 125, 115, 113, 119, 117, 107, 105, 111, 109, 99, 97, 103, 101, 155, 153, 159, 157, 147, 145, 151, 149, 139, 137, 143, 141, 131, 129, 135, 133, 187, 185, 191, 189, 179, 177, 183, 181, 171, 169, 175, 173, 163, 161, 167, 165, 219, 217, 223, 221, 211, 209, 215, 213, 203, 201, 207, 205, 195, 193, 199, 197, 251, 249, 0xFF, 253, 243, 241, 247, 245, 235, 233, 239, 237, 227, 225, 231, 229];
private static const _Xtime9:Array = [0, 9, 18, 27, 36, 45, 54, 63, 72, 65, 90, 83, 108, 101, 126, 119, 144, 153, 130, 139, 180, 189, 166, 175, 216, 209, 202, 195, 252, 245, 238, 231, 59, 50, 41, 32, 31, 22, 13, 4, 115, 122, 97, 104, 87, 94, 69, 76, 171, 162, 185, 176, 143, 134, 157, 148, 227, 234, 241, 248, 199, 206, 213, 220, 118, 127, 100, 109, 82, 91, 64, 73, 62, 55, 44, 37, 26, 19, 8, 1, 230, 239, 244, 253, 194, 203, 208, 217, 174, 167, 188, 181, 138, 131, 152, 145, 77, 68, 95, 86, 105, 96, 123, 114, 5, 12, 23, 30, 33, 40, 51, 58, 221, 212, 207, 198, 249, 240, 235, 226, 149, 156, 135, 142, 177, 184, 163, 170, 236, 229, 254, 247, 200, 193, 218, 211, 164, 173, 182, 191, 128, 137, 146, 155, 124, 117, 110, 103, 88, 81, 74, 67, 52, 61, 38, 47, 16, 25, 2, 11, 215, 222, 197, 204, 243, 250, 225, 232, 159, 150, 141, 132, 187, 178, 169, 160, 71, 78, 85, 92, 99, 106, 113, 120, 15, 6, 29, 20, 43, 34, 57, 48, 154, 147, 136, 129, 190, 183, 172, 165, 210, 219, 192, 201, 246, 0xFF, 228, 237, 10, 3, 24, 17, 46, 39, 60, 53, 66, 75, 80, 89, 102, 111, 116, 125, 161, 168, 179, 186, 133, 140, 151, 158, 233, 224, 251, 242, 205, 196, 223, 214, 49, 56, 35, 42, 21, 28, 7, 14, 121, 112, 107, 98, 93, 84, 79, 70];
private static const Nb:uint = 4;
private static const _XtimeB:Array = [0, 11, 22, 29, 44, 39, 58, 49, 88, 83, 78, 69, 116, 127, 98, 105, 176, 187, 166, 173, 156, 151, 138, 129, 232, 227, 254, 245, 196, 207, 210, 217, 123, 112, 109, 102, 87, 92, 65, 74, 35, 40, 53, 62, 15, 4, 25, 18, 203, 192, 221, 214, 231, 236, 241, 250, 147, 152, 133, 142, 191, 180, 169, 162, 246, 253, 224, 235, 218, 209, 204, 199, 174, 165, 184, 179, 130, 137, 148, 159, 70, 77, 80, 91, 106, 97, 124, 119, 30, 21, 8, 3, 50, 57, 36, 47, 141, 134, 155, 144, 161, 170, 183, 188, 213, 222, 195, 200, 249, 242, 239, 228, 61, 54, 43, 32, 17, 26, 7, 12, 101, 110, 115, 120, 73, 66, 95, 84, 247, 252, 225, 234, 219, 208, 205, 198, 175, 164, 185, 178, 131, 136, 149, 158, 71, 76, 81, 90, 107, 96, 125, 118, 31, 20, 9, 2, 51, 56, 37, 46, 140, 135, 154, 145, 160, 171, 182, 189, 212, 223, 194, 201, 248, 243, 238, 229, 60, 55, 42, 33, 16, 27, 6, 13, 100, 111, 114, 121, 72, 67, 94, 85, 1, 10, 23, 28, 45, 38, 59, 48, 89, 82, 79, 68, 117, 126, 99, 104, 177, 186, 167, 172, 157, 150, 139, 128, 233, 226, 0xFF, 244, 197, 206, 211, 216, 122, 113, 108, 103, 86, 93, 64, 75, 34, 41, 52, 63, 14, 5, 24, 19, 202, 193, 220, 215, 230, 237, 240, 251, 146, 153, 132, 143, 190, 181, 168, 163];
private static const _XtimeE:Array = [0, 14, 28, 18, 56, 54, 36, 42, 112, 126, 108, 98, 72, 70, 84, 90, 224, 238, 252, 242, 216, 214, 196, 202, 144, 158, 140, 130, 168, 166, 180, 186, 219, 213, 199, 201, 227, 237, 0xFF, 241, 171, 165, 183, 185, 147, 157, 143, 129, 59, 53, 39, 41, 3, 13, 31, 17, 75, 69, 87, 89, 115, 125, 111, 97, 173, 163, 177, 191, 149, 155, 137, 135, 221, 211, 193, 207, 229, 235, 249, 247, 77, 67, 81, 95, 117, 123, 105, 103, 61, 51, 33, 47, 5, 11, 25, 23, 118, 120, 106, 100, 78, 64, 82, 92, 6, 8, 26, 20, 62, 48, 34, 44, 150, 152, 138, 132, 174, 160, 178, 188, 230, 232, 250, 244, 222, 208, 194, 204, 65, 79, 93, 83, 121, 119, 101, 107, 49, 63, 45, 35, 9, 7, 21, 27, 161, 175, 189, 179, 153, 151, 133, 139, 209, 223, 205, 195, 233, 231, 245, 251, 154, 148, 134, 136, 162, 172, 190, 176, 234, 228, 246, 248, 210, 220, 206, 192, 122, 116, 102, 104, 66, 76, 94, 80, 10, 4, 22, 24, 50, 60, 46, 32, 236, 226, 240, 254, 212, 218, 200, 198, 156, 146, 128, 142, 164, 170, 184, 182, 12, 2, 16, 30, 52, 58, 40, 38, 124, 114, 96, 110, 68, 74, 88, 86, 55, 57, 43, 37, 15, 1, 19, 29, 71, 73, 91, 85, 127, 113, 99, 109, 215, 217, 203, 197, 239, 225, 243, 253, 167, 169, 187, 181, 159, 145, 131, 141];
private static const _Xtime2Sbox:Array = [198, 248, 238, 246, 0xFF, 214, 222, 145, 96, 2, 206, 86, 231, 181, 77, 236, 143, 31, 137, 250, 239, 178, 142, 251, 65, 179, 95, 69, 35, 83, 228, 155, 117, 225, 61, 76, 108, 126, 245, 131, 104, 81, 209, 249, 226, 171, 98, 42, 8, 149, 70, 157, 48, 55, 10, 47, 14, 36, 27, 223, 205, 78, 127, 234, 18, 29, 88, 52, 54, 220, 180, 91, 164, 118, 183, 125, 82, 221, 94, 19, 166, 185, 0, 193, 64, 227, 121, 182, 212, 141, 103, 114, 148, 152, 176, 133, 187, 197, 79, 237, 134, 154, 102, 17, 138, 233, 4, 254, 160, 120, 37, 75, 162, 93, 128, 5, 63, 33, 112, 241, 99, 119, 175, 66, 32, 229, 253, 191, 129, 24, 38, 195, 190, 53, 136, 46, 147, 85, 252, 122, 200, 186, 50, 230, 192, 25, 158, 163, 68, 84, 59, 11, 140, 199, 107, 40, 167, 188, 22, 173, 219, 100, 116, 20, 146, 12, 72, 184, 159, 189, 67, 196, 57, 49, 211, 242, 213, 139, 110, 218, 1, 177, 156, 73, 216, 172, 243, 207, 202, 244, 71, 16, 111, 240, 74, 92, 56, 87, 115, 151, 203, 161, 232, 62, 150, 97, 13, 15, 224, 124, 113, 204, 144, 6, 247, 28, 194, 106, 174, 105, 23, 153, 58, 39, 217, 235, 43, 34, 210, 169, 7, 51, 45, 60, 21, 201, 135, 170, 80, 165, 3, 89, 9, 26, 101, 215, 132, 208, 130, 41, 90, 30, 123, 168, 109, 44];
private static const _Xtime3Sbox:Array = [165, 132, 153, 141, 13, 189, 177, 84, 80, 3, 169, 125, 25, 98, 230, 154, 69, 157, 64, 135, 21, 235, 201, 11, 236, 103, 253, 234, 191, 247, 150, 91, 194, 28, 174, 106, 90, 65, 2, 79, 92, 244, 52, 8, 147, 115, 83, 63, 12, 82, 101, 94, 40, 161, 15, 181, 9, 54, 155, 61, 38, 105, 205, 159, 27, 158, 116, 46, 45, 178, 238, 251, 246, 77, 97, 206, 123, 62, 113, 151, 245, 104, 0, 44, 96, 31, 200, 237, 190, 70, 217, 75, 222, 212, 232, 74, 107, 42, 229, 22, 197, 215, 85, 148, 207, 16, 6, 129, 240, 68, 186, 227, 243, 254, 192, 138, 173, 188, 72, 4, 223, 193, 117, 99, 48, 26, 14, 109, 76, 20, 53, 47, 225, 162, 204, 57, 87, 242, 130, 71, 172, 231, 43, 149, 160, 152, 209, 127, 102, 126, 171, 131, 202, 41, 211, 60, 121, 226, 29, 118, 59, 86, 78, 30, 219, 10, 108, 228, 93, 110, 239, 166, 168, 164, 55, 139, 50, 67, 89, 183, 140, 100, 210, 224, 180, 250, 7, 37, 175, 142, 233, 24, 213, 136, 111, 114, 36, 241, 199, 81, 35, 124, 156, 33, 221, 220, 134, 133, 144, 66, 196, 170, 216, 5, 1, 18, 163, 95, 249, 208, 145, 88, 39, 185, 56, 19, 179, 51, 187, 112, 137, 167, 182, 34, 146, 32, 73, 0xFF, 120, 122, 143, 248, 128, 23, 218, 49, 198, 184, 195, 176, 119, 17, 203, 252, 214, 58];
private static const _InvSbox:Array = [82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, 124, 227, 57, 130, 155, 47, 0xFF, 135, 52, 142, 67, 68, 196, 222, 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209, 37, 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, 204, 93, 101, 182, 146, 108, 112, 72, 80, 253, 237, 185, 218, 94, 21, 70, 87, 167, 141, 157, 132, 144, 216, 171, 0, 140, 188, 211, 10, 247, 228, 88, 5, 184, 179, 69, 6, 208, 44, 30, 143, 202, 63, 15, 2, 193, 175, 189, 3, 1, 19, 138, 107, 58, 145, 17, 65, 79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230, 115, 150, 172, 116, 34, 231, 173, 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, 71, 241, 26, 113, 29, 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, 252, 86, 62, 75, 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, 31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125];
private static const _XtimeD:Array = [0, 13, 26, 23, 52, 57, 46, 35, 104, 101, 114, 127, 92, 81, 70, 75, 208, 221, 202, 199, 228, 233, 254, 243, 184, 181, 162, 175, 140, 129, 150, 155, 187, 182, 161, 172, 143, 130, 149, 152, 211, 222, 201, 196, 231, 234, 253, 240, 107, 102, 113, 124, 95, 82, 69, 72, 3, 14, 25, 20, 55, 58, 45, 32, 109, 96, 119, 122, 89, 84, 67, 78, 5, 8, 31, 18, 49, 60, 43, 38, 189, 176, 167, 170, 137, 132, 147, 158, 213, 216, 207, 194, 225, 236, 251, 246, 214, 219, 204, 193, 226, 239, 248, 245, 190, 179, 164, 169, 138, 135, 144, 157, 6, 11, 28, 17, 50, 63, 40, 37, 110, 99, 116, 121, 90, 87, 64, 77, 218, 215, 192, 205, 238, 227, 244, 249, 178, 191, 168, 165, 134, 139, 156, 145, 10, 7, 16, 29, 62, 51, 36, 41, 98, 111, 120, 117, 86, 91, 76, 65, 97, 108, 123, 118, 85, 88, 79, 66, 9, 4, 19, 30, 61, 48, 39, 42, 177, 188, 171, 166, 133, 136, 159, 146, 217, 212, 195, 206, 237, 224, 247, 250, 183, 186, 173, 160, 131, 142, 153, 148, 223, 210, 197, 200, 235, 230, 241, 252, 103, 106, 125, 112, 83, 94, 73, 68, 15, 2, 21, 24, 59, 54, 33, 44, 12, 1, 22, 27, 56, 53, 34, 47, 100, 105, 126, 115, 80, 93, 74, 71, 220, 209, 198, 203, 232, 229, 242, 0xFF, 180, 185, 174, 163, 128, 141, 154, 151];
private static const _Sbox:Array = [99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 0xFF, 243, 210, 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22];
private static var XtimeE:ByteArray = new ByteArray();
private static var i:uint = 0;
private static var Xtime2Sbox:ByteArray = new ByteArray();
private static var Xtime3Sbox:ByteArray = new ByteArray();
private static var _Rcon:Array = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54];
private static var Sbox:ByteArray = new ByteArray();
private static var Rcon:ByteArray = new ByteArray();
private static var InvSbox:ByteArray = new ByteArray();
private static var Xtime2:ByteArray = new ByteArray();
private static var Xtime9:ByteArray = new ByteArray();
private static var XtimeB:ByteArray = new ByteArray();
private static var XtimeD:ByteArray = new ByteArray();
public function AESKey(key:ByteArray){
super();
tmp = new ByteArray();
state = new ByteArray();
keyLength = key.length;
this.key = new ByteArray();
this.key.writeBytes(key);
expandKey();
}
public function toString():String{
return (("aes" + (8 * keyLength)));
}
public function decrypt(block:ByteArray, index:uint=0):void{
var round:uint;
state.position = 0;
state.writeBytes(block, index, (Nb * 4));
addRoundKey(key, ((Nr * Nb) * 4));
invShiftRows();
round = Nr;
while (round--) {
addRoundKey(key, ((round * Nb) * 4));
if (round){
invMixSubColumns();
};
};
block.position = index;
block.writeBytes(state);
}
protected function invShiftRows():void{
var tmp:uint;
state[0] = InvSbox[state[0]];
state[4] = InvSbox[state[4]];
state[8] = InvSbox[state[8]];
state[12] = InvSbox[state[12]];
tmp = InvSbox[state[13]];
state[13] = InvSbox[state[9]];
state[9] = InvSbox[state[5]];
state[5] = InvSbox[state[1]];
state[1] = tmp;
tmp = InvSbox[state[2]];
state[2] = InvSbox[state[10]];
state[10] = tmp;
tmp = InvSbox[state[6]];
state[6] = InvSbox[state[14]];
state[14] = tmp;
tmp = InvSbox[state[3]];
state[3] = InvSbox[state[7]];
state[7] = InvSbox[state[11]];
state[11] = InvSbox[state[15]];
state[15] = tmp;
}
public function dispose():void{
var i:uint;
var r:Random;
r = new Random();
i = 0;
while (i < key.length) {
key[i] = r.nextByte();
i++;
};
Nr = r.nextByte();
i = 0;
while (i < state.length) {
state[i] = r.nextByte();
i++;
};
i = 0;
while (i < tmp.length) {
tmp[i] = r.nextByte();
i++;
};
key.length = 0;
keyLength = 0;
state.length = 0;
tmp.length = 0;
key = null;
state = null;
tmp = null;
Nr = 0;
Memory.gc();
}
protected function invMixSubColumns():void{
var i:uint;
tmp.length = 0;
tmp[0] = (((XtimeE[state[0]] ^ XtimeB[state[1]]) ^ XtimeD[state[2]]) ^ Xtime9[state[3]]);
tmp[5] = (((Xtime9[state[0]] ^ XtimeE[state[1]]) ^ XtimeB[state[2]]) ^ XtimeD[state[3]]);
tmp[10] = (((XtimeD[state[0]] ^ Xtime9[state[1]]) ^ XtimeE[state[2]]) ^ XtimeB[state[3]]);
tmp[15] = (((XtimeB[state[0]] ^ XtimeD[state[1]]) ^ Xtime9[state[2]]) ^ XtimeE[state[3]]);
tmp[4] = (((XtimeE[state[4]] ^ XtimeB[state[5]]) ^ XtimeD[state[6]]) ^ Xtime9[state[7]]);
tmp[9] = (((Xtime9[state[4]] ^ XtimeE[state[5]]) ^ XtimeB[state[6]]) ^ XtimeD[state[7]]);
tmp[14] = (((XtimeD[state[4]] ^ Xtime9[state[5]]) ^ XtimeE[state[6]]) ^ XtimeB[state[7]]);
tmp[3] = (((XtimeB[state[4]] ^ XtimeD[state[5]]) ^ Xtime9[state[6]]) ^ XtimeE[state[7]]);
tmp[8] = (((XtimeE[state[8]] ^ XtimeB[state[9]]) ^ XtimeD[state[10]]) ^ Xtime9[state[11]]);
tmp[13] = (((Xtime9[state[8]] ^ XtimeE[state[9]]) ^ XtimeB[state[10]]) ^ XtimeD[state[11]]);
tmp[2] = (((XtimeD[state[8]] ^ Xtime9[state[9]]) ^ XtimeE[state[10]]) ^ XtimeB[state[11]]);
tmp[7] = (((XtimeB[state[8]] ^ XtimeD[state[9]]) ^ Xtime9[state[10]]) ^ XtimeE[state[11]]);
tmp[12] = (((XtimeE[state[12]] ^ XtimeB[state[13]]) ^ XtimeD[state[14]]) ^ Xtime9[state[15]]);
tmp[1] = (((Xtime9[state[12]] ^ XtimeE[state[13]]) ^ XtimeB[state[14]]) ^ XtimeD[state[15]]);
tmp[6] = (((XtimeD[state[12]] ^ Xtime9[state[13]]) ^ XtimeE[state[14]]) ^ XtimeB[state[15]]);
tmp[11] = (((XtimeB[state[12]] ^ XtimeD[state[13]]) ^ Xtime9[state[14]]) ^ XtimeE[state[15]]);
i = 0;
while (i < (4 * Nb)) {
state[i] = InvSbox[tmp[i]];
i++;
};
}
private function expandKey():void{
var tmp0:uint;
var tmp1:uint;
var tmp2:uint;
var tmp3:uint;
var tmp4:uint;
var idx:uint;
var Nk:uint;
Nk = (key.length / 4);
Nr = (Nk + 6);
idx = Nk;
while (idx < (Nb * (Nr + 1))) {
tmp0 = key[((4 * idx) - 4)];
tmp1 = key[((4 * idx) - 3)];
tmp2 = key[((4 * idx) - 2)];
tmp3 = key[((4 * idx) - 1)];
if (!(idx % Nk)){
tmp4 = tmp3;
tmp3 = Sbox[tmp0];
tmp0 = (Sbox[tmp1] ^ Rcon[(idx / Nk)]);
tmp1 = Sbox[tmp2];
tmp2 = Sbox[tmp4];
} else {
if ((((Nk > 6)) && (((idx % Nk) == 4)))){
tmp0 = Sbox[tmp0];
tmp1 = Sbox[tmp1];
tmp2 = Sbox[tmp2];
tmp3 = Sbox[tmp3];
};
};
key[((4 * idx) + 0)] = (key[(((4 * idx) - (4 * Nk)) + 0)] ^ tmp0);
key[((4 * idx) + 1)] = (key[(((4 * idx) - (4 * Nk)) + 1)] ^ tmp1);
key[((4 * idx) + 2)] = (key[(((4 * idx) - (4 * Nk)) + 2)] ^ tmp2);
key[((4 * idx) + 3)] = (key[(((4 * idx) - (4 * Nk)) + 3)] ^ tmp3);
idx++;
};
}
protected function addRoundKey(key:ByteArray, offset:uint):void{
var idx:uint;
idx = 0;
while (idx < 16) {
state[idx] = (state[idx] ^ key[(idx + offset)]);
idx++;
};
}
public function encrypt(block:ByteArray, index:uint=0):void{
var round:uint;
state.position = 0;
state.writeBytes(block, index, (Nb * 4));
addRoundKey(key, 0);
round = 1;
while (round < (Nr + 1)) {
if (round < Nr){
mixSubColumns();
} else {
shiftRows();
};
addRoundKey(key, ((round * Nb) * 4));
round++;
};
block.position = index;
block.writeBytes(state);
}
protected function mixSubColumns():void{
tmp.length = 0;
tmp[0] = (((Xtime2Sbox[state[0]] ^ Xtime3Sbox[state[5]]) ^ Sbox[state[10]]) ^ Sbox[state[15]]);
tmp[1] = (((Sbox[state[0]] ^ Xtime2Sbox[state[5]]) ^ Xtime3Sbox[state[10]]) ^ Sbox[state[15]]);
tmp[2] = (((Sbox[state[0]] ^ Sbox[state[5]]) ^ Xtime2Sbox[state[10]]) ^ Xtime3Sbox[state[15]]);
tmp[3] = (((Xtime3Sbox[state[0]] ^ Sbox[state[5]]) ^ Sbox[state[10]]) ^ Xtime2Sbox[state[15]]);
tmp[4] = (((Xtime2Sbox[state[4]] ^ Xtime3Sbox[state[9]]) ^ Sbox[state[14]]) ^ Sbox[state[3]]);
tmp[5] = (((Sbox[state[4]] ^ Xtime2Sbox[state[9]]) ^ Xtime3Sbox[state[14]]) ^ Sbox[state[3]]);
tmp[6] = (((Sbox[state[4]] ^ Sbox[state[9]]) ^ Xtime2Sbox[state[14]]) ^ Xtime3Sbox[state[3]]);
tmp[7] = (((Xtime3Sbox[state[4]] ^ Sbox[state[9]]) ^ Sbox[state[14]]) ^ Xtime2Sbox[state[3]]);
tmp[8] = (((Xtime2Sbox[state[8]] ^ Xtime3Sbox[state[13]]) ^ Sbox[state[2]]) ^ Sbox[state[7]]);
tmp[9] = (((Sbox[state[8]] ^ Xtime2Sbox[state[13]]) ^ Xtime3Sbox[state[2]]) ^ Sbox[state[7]]);
tmp[10] = (((Sbox[state[8]] ^ Sbox[state[13]]) ^ Xtime2Sbox[state[2]]) ^ Xtime3Sbox[state[7]]);
tmp[11] = (((Xtime3Sbox[state[8]] ^ Sbox[state[13]]) ^ Sbox[state[2]]) ^ Xtime2Sbox[state[7]]);
tmp[12] = (((Xtime2Sbox[state[12]] ^ Xtime3Sbox[state[1]]) ^ Sbox[state[6]]) ^ Sbox[state[11]]);
tmp[13] = (((Sbox[state[12]] ^ Xtime2Sbox[state[1]]) ^ Xtime3Sbox[state[6]]) ^ Sbox[state[11]]);
tmp[14] = (((Sbox[state[12]] ^ Sbox[state[1]]) ^ Xtime2Sbox[state[6]]) ^ Xtime3Sbox[state[11]]);
tmp[15] = (((Xtime3Sbox[state[12]] ^ Sbox[state[1]]) ^ Sbox[state[6]]) ^ Xtime2Sbox[state[11]]);
state.position = 0;
state.writeBytes(tmp, 0, (Nb * 4));
}
protected function shiftRows():void{
var tmp:uint;
state[0] = Sbox[state[0]];
state[4] = Sbox[state[4]];
state[8] = Sbox[state[8]];
state[12] = Sbox[state[12]];
tmp = Sbox[state[1]];
state[1] = Sbox[state[5]];
state[5] = Sbox[state[9]];
state[9] = Sbox[state[13]];
state[13] = tmp;
tmp = Sbox[state[2]];
state[2] = Sbox[state[10]];
state[10] = tmp;
tmp = Sbox[state[6]];
state[6] = Sbox[state[14]];
state[14] = tmp;
tmp = Sbox[state[15]];
state[15] = Sbox[state[11]];
state[11] = Sbox[state[7]];
state[7] = Sbox[state[3]];
state[3] = tmp;
}
public function getBlockSize():uint{
return (16);
}
while (i < 0x0100) {
Sbox[i] = _Sbox[i];
InvSbox[i] = _InvSbox[i];
Xtime2Sbox[i] = _Xtime2Sbox[i];
Xtime3Sbox[i] = _Xtime3Sbox[i];
Xtime2[i] = _Xtime2[i];
Xtime9[i] = _Xtime9[i];
XtimeB[i] = _XtimeB[i];
XtimeD[i] = _XtimeD[i];
XtimeE[i] = _XtimeE[i];
i++;
};
i = 0;
while (i < _Rcon.length) {
Rcon[i] = _Rcon[i];
i++;
};
}
}//package com.hurlant.crypto.symmetric
Section 26
//BlowFishKey (com.hurlant.crypto.symmetric.BlowFishKey)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.util.*;
public class BlowFishKey implements ISymmetricKey {
private var S3:Array;
private var S2:Array;
private var P:Array;
private var key:ByteArray;// = null
private var S0:Array;
private var S1:Array;
private static const KP:Array = [608135816, 2242054355, 320440878, 57701188, 2752067618, 698298832, 137296536, 3964562569, 1160258022, 953160567, 3193202383, 887688300, 3232508343, 3380367581, 1065670069, 3041331479, 2450970073, 2306472731];
private static const KS0:Array = [3509652390, 2564797868, 805139163, 3491422135, 3101798381, 1780907670, 3128725573, 4046225305, 614570311, 3012652279, 134345442, 2240740374, 1667834072, 1901547113, 2757295779, 4103290238, 227898511, 1921955416, 1904987480, 2182433518, 2069144605, 3260701109, 2620446009, 720527379, 3318853667, 677414384, 3393288472, 3101374703, 2390351024, 1614419982, 1822297739, 2954791486, 3608508353, 3174124327, 2024746970, 1432378464, 3864339955, 2857741204, 1464375394, 1676153920, 1439316330, 715854006, 3033291828, 289532110, 2706671279, 2087905683, 3018724369, 1668267050, 732546397, 1947742710, 3462151702, 2609353502, 2950085171, 1814351708, 2050118529, 680887927, 999245976, 1800124847, 3300911131, 1713906067, 1641548236, 4213287313, 1216130144, 1575780402, 4018429277, 3917837745, 3693486850, 3949271944, 596196993, 3549867205, 258830323, 2213823033, 772490370, 2760122372, 1774776394, 2652871518, 566650946, 4142492826, 1728879713, 2882767088, 1783734482, 3629395816, 2517608232, 2874225571, 1861159788, 326777828, 3124490320, 2130389656, 2716951837, 967770486, 1724537150, 2185432712, 2364442137, 1164943284, 2105845187, 998989502, 3765401048, 2244026483, 1075463327, 1455516326, 1322494562, 910128902, 469688178, 1117454909, 936433444, 3490320968, 3675253459, 1240580251, 122909385, 2157517691, 634681816, 4142456567, 3825094682, 3061402683, 2540495037, 79693498, 3249098678, 1084186820, 1583128258, 426386531, 1761308591, 1047286709, 322548459, 995290223, 1845252383, 2603652396, 3431023940, 2942221577, 3202600964, 3727903485, 1712269319, 422464435, 3234572375, 1170764815, 3523960633, 3117677531, 1434042557, 442511882, 3600875718, 1076654713, 1738483198, 4213154764, 2393238008, 3677496056, 1014306527, 4251020053, 793779912, 2902807211, 842905082, 4246964064, 1395751752, 1040244610, 2656851899, 3396308128, 445077038, 3742853595, 3577915638, 679411651, 2892444358, 2354009459, 1767581616, 3150600392, 3791627101, 3102740896, 284835224, 4246832056, 1258075500, 768725851, 2589189241, 3069724005, 3532540348, 1274779536, 3789419226, 2764799539, 1660621633, 3471099624, 4011903706, 913787905, 3497959166, 737222580, 2514213453, 2928710040, 3937242737, 1804850592, 3499020752, 2949064160, 2386320175, 2390070455, 2415321851, 4061277028, 2290661394, 2416832540, 1336762016, 1754252060, 3520065937, 3014181293, 791618072, 3188594551, 3933548030, 2332172193, 3852520463, 3043980520, 413987798, 3465142937, 3030929376, 4245938359, 2093235073, 3534596313, 375366246, 2157278981, 2479649556, 555357303, 3870105701, 2008414854, 3344188149, 4221384143, 3956125452, 2067696032, 3594591187, 2921233993, 2428461, 544322398, 577241275, 1471733935, 610547355, 4027169054, 1432588573, 1507829418, 2025931657, 3646575487, 545086370, 48609733, 2200306550, 1653985193, 298326376, 1316178497, 3007786442, 2064951626, 458293330, 2589141269, 3591329599, 3164325604, 727753846, 2179363840, 146436021, 1461446943, 4069977195, 705550613, 3059967265, 3887724982, 4281599278, 3313849956, 1404054877, 2845806497, 146425753, 1854211946];
private static const KS1:Array = [1266315497, 3048417604, 3681880366, 3289982499, 2909710000, 1235738493, 2632868024, 2414719590, 3970600049, 1771706367, 1449415276, 3266420449, 422970021, 1963543593, 2690192192, 3826793022, 1062508698, 1531092325, 1804592342, 2583117782, 2714934279, 4024971509, 1294809318, 4028980673, 1289560198, 2221992742, 1669523910, 35572830, 157838143, 1052438473, 1016535060, 1802137761, 1753167236, 1386275462, 3080475397, 2857371447, 1040679964, 2145300060, 2390574316, 1461121720, 2956646967, 4031777805, 4028374788, 33600511, 2920084762, 1018524850, 629373528, 3691585981, 3515945977, 2091462646, 2486323059, 586499841, 988145025, 935516892, 3367335476, 2599673255, 2839830854, 265290510, 3972581182, 2759138881, 3795373465, 1005194799, 847297441, 406762289, 1314163512, 1332590856, 1866599683, 4127851711, 750260880, 613907577, 1450815602, 3165620655, 3734664991, 3650291728, 3012275730, 3704569646, 1427272223, 778793252, 1343938022, 2676280711, 2052605720, 1946737175, 3164576444, 3914038668, 3967478842, 3682934266, 1661551462, 3294938066, 4011595847, 840292616, 3712170807, 616741398, 312560963, 711312465, 1351876610, 322626781, 1910503582, 271666773, 2175563734, 1594956187, 70604529, 3617834859, 1007753275, 1495573769, 4069517037, 2549218298, 2663038764, 504708206, 2263041392, 3941167025, 2249088522, 1514023603, 1998579484, 1312622330, 694541497, 2582060303, 2151582166, 1382467621, 776784248, 2618340202, 3323268794, 2497899128, 2784771155, 503983604, 4076293799, 907881277, 423175695, 432175456, 1378068232, 4145222326, 3954048622, 3938656102, 3820766613, 2793130115, 2977904593, 26017576, 3274890735, 3194772133, 1700274565, 1756076034, 4006520079, 3677328699, 720338349, 1533947780, 354530856, 688349552, 3973924725, 1637815568, 332179504, 3949051286, 53804574, 2852348879, 3044236432, 1282449977, 3583942155, 3416972820, 4006381244, 1617046695, 2628476075, 3002303598, 1686838959, 431878346, 2686675385, 1700445008, 1080580658, 1009431731, 832498133, 3223435511, 2605976345, 2271191193, 2516031870, 1648197032, 4164389018, 2548247927, 300782431, 375919233, 238389289, 3353747414, 2531188641, 2019080857, 1475708069, 455242339, 2609103871, 448939670, 3451063019, 1395535956, 2413381860, 1841049896, 1491858159, 885456874, 4264095073, 4001119347, 1565136089, 3898914787, 1108368660, 540939232, 1173283510, 2745871338, 3681308437, 4207628240, 3343053890, 4016749493, 1699691293, 1103962373, 3625875870, 2256883143, 3830138730, 1031889488, 3479347698, 1535977030, 4236805024, 3251091107, 2132092099, 1774941330, 1199868427, 1452454533, 157007616, 2904115357, 342012276, 595725824, 1480756522, 206960106, 497939518, 591360097, 863170706, 2375253569, 3596610801, 1814182875, 2094937945, 3421402208, 1082520231, 3463918190, 2785509508, 435703966, 3908032597, 1641649973, 2842273706, 3305899714, 1510255612, 2148256476, 2655287854, 3276092548, 4258621189, 236887753, 3681803219, 274041037, 1734335097, 3815195456, 3317970021, 1899903192, 1026095262, 4050517792, 356393447, 2410691914, 3873677099, 3682840055];
private static const KS3:Array = [976866871, 3556439503, 2881648439, 1522871579, 1555064734, 1336096578, 3548522304, 2579274686, 3574697629, 3205460757, 3593280638, 3338716283, 3079412587, 564236357, 2993598910, 1781952180, 1464380207, 3163844217, 3332601554, 1699332808, 1393555694, 1183702653, 3581086237, 1288719814, 691649499, 2847557200, 2895455976, 3193889540, 2717570544, 1781354906, 1676643554, 2592534050, 3230253752, 1126444790, 2770207658, 2633158820, 2210423226, 2615765581, 2414155088, 3127139286, 673620729, 2805611233, 1269405062, 4015350505, 3341807571, 4149409754, 1057255273, 2012875353, 2162469141, 2276492801, 2601117357, 993977747, 3918593370, 2654263191, 753973209, 36408145, 2530585658, 25011837, 3520020182, 2088578344, 530523599, 2918365339, 1524020338, 1518925132, 3760827505, 3759777254, 1202760957, 3985898139, 3906192525, 674977740, 4174734889, 2031300136, 2019492241, 3983892565, 4153806404, 3822280332, 352677332, 2297720250, 60907813, 90501309, 3286998549, 1016092578, 2535922412, 2839152426, 457141659, 509813237, 4120667899, 652014361, 1966332200, 2975202805, 55981186, 2327461051, 676427537, 3255491064, 2882294119, 3433927263, 1307055953, 942726286, 933058658, 2468411793, 3933900994, 4215176142, 1361170020, 2001714738, 2830558078, 3274259782, 1222529897, 1679025792, 2729314320, 3714953764, 1770335741, 151462246, 3013232138, 1682292957, 1483529935, 471910574, 1539241949, 458788160, 3436315007, 1807016891, 3718408830, 978976581, 1043663428, 3165965781, 1927990952, 4200891579, 2372276910, 3208408903, 3533431907, 1412390302, 2931980059, 4132332400, 1947078029, 3881505623, 4168226417, 2941484381, 1077988104, 1320477388, 886195818, 18198404, 3786409000, 2509781533, 112762804, 3463356488, 1866414978, 891333506, 18488651, 661792760, 1628790961, 3885187036, 3141171499, 876946877, 2693282273, 1372485963, 791857591, 2686433993, 3759982718, 3167212022, 3472953795, 2716379847, 445679433, 3561995674, 3504004811, 3574258232, 54117162, 3331405415, 2381918588, 3769707343, 4154350007, 1140177722, 4074052095, 668550556, 3214352940, 367459370, 261225585, 2610173221, 4209349473, 3468074219, 3265815641, 314222801, 3066103646, 3808782860, 282218597, 3406013506, 3773591054, 379116347, 1285071038, 846784868, 2669647154, 3771962079, 3550491691, 2305946142, 453669953, 1268987020, 3317592352, 3279303384, 3744833421, 2610507566, 3859509063, 266596637, 3847019092, 517658769, 3462560207, 3443424879, 370717030, 4247526661, 2224018117, 4143653529, 4112773975, 2788324899, 2477274417, 1456262402, 2901442914, 1517677493, 1846949527, 2295493580, 3734397586, 2176403920, 1280348187, 1908823572, 3871786941, 846861322, 1172426758, 3287448474, 3383383037, 1655181056, 3139813346, 901632758, 1897031941, 2986607138, 3066810236, 3447102507, 1393639104, 373351379, 950779232, 625454576, 3124240540, 4148612726, 2007998917, 544563296, 2244738638, 2330496472, 2058025392, 1291430526, 424198748, 50039436, 29584100, 3605783033, 2429876329, 2791104160, 1057563949, 3255363231, 3075367218, 3463963227, 1469046755, 985887462];
private static const ROUNDS:uint = 16;
private static const KS2:Array = [3913112168, 2491498743, 4132185628, 2489919796, 1091903735, 1979897079, 3170134830, 3567386728, 3557303409, 857797738, 1136121015, 1342202287, 507115054, 2535736646, 337727348, 3213592640, 1301675037, 2528481711, 1895095763, 1721773893, 3216771564, 62756741, 2142006736, 835421444, 2531993523, 1442658625, 3659876326, 2882144922, 676362277, 1392781812, 170690266, 3921047035, 1759253602, 3611846912, 1745797284, 664899054, 1329594018, 3901205900, 3045908486, 2062866102, 2865634940, 3543621612, 3464012697, 1080764994, 553557557, 3656615353, 3996768171, 991055499, 499776247, 1265440854, 648242737, 3940784050, 980351604, 3713745714, 1749149687, 3396870395, 4211799374, 3640570775, 1161844396, 3125318951, 1431517754, 545492359, 4268468663, 3499529547, 1437099964, 2702547544, 3433638243, 2581715763, 2787789398, 1060185593, 1593081372, 2418618748, 4260947970, 69676912, 2159744348, 86519011, 2512459080, 3838209314, 1220612927, 3339683548, 133810670, 1090789135, 1078426020, 1569222167, 845107691, 3583754449, 4072456591, 1091646820, 628848692, 1613405280, 3757631651, 526609435, 236106946, 48312990, 2942717905, 3402727701, 1797494240, 859738849, 992217954, 4005476642, 2243076622, 3870952857, 3732016268, 765654824, 3490871365, 2511836413, 1685915746, 3888969200, 1414112111, 2273134842, 3281911079, 4080962846, 172450625, 2569994100, 980381355, 4109958455, 2819808352, 2716589560, 2568741196, 3681446669, 3329971472, 1835478071, 660984891, 3704678404, 4045999559, 3422617507, 3040415634, 1762651403, 1719377915, 3470491036, 2693910283, 3642056355, 3138596744, 1364962596, 2073328063, 1983633131, 926494387, 3423689081, 2150032023, 4096667949, 1749200295, 3328846651, 309677260, 2016342300, 1779581495, 3079819751, 111262694, 1274766160, 443224088, 298511866, 1025883608, 3806446537, 1145181785, 168956806, 3641502830, 3584813610, 1689216846, 3666258015, 3200248200, 1692713982, 2646376535, 4042768518, 1618508792, 1610833997, 3523052358, 4130873264, 2001055236, 3610705100, 2202168115, 4028541809, 2961195399, 1006657119, 2006996926, 3186142756, 1430667929, 3210227297, 1314452623, 4074634658, 4101304120, 2273951170, 1399257539, 3367210612, 3027628629, 1190975929, 2062231137, 2333990788, 2221543033, 2438960610, 1181637006, 548689776, 2362791313, 3372408396, 3104550113, 3145860560, 296247880, 1970579870, 3078560182, 3769228297, 1714227617, 3291629107, 3898220290, 166772364, 1251581989, 493813264, 448347421, 195405023, 2709975567, 677966185, 3703036547, 1463355134, 2715995803, 1338867538, 1343315457, 2802222074, 2684532164, 233230375, 2599980071, 2000651841, 3277868038, 1638401717, 4028070440, 3237316320, 6314154, 819756386, 300326615, 590932579, 1405279636, 3267499572, 3150704214, 2428286686, 3959192993, 3461946742, 1862657033, 1266418056, 963775037, 2089974820, 2263052895, 1917689273, 448879540, 3550394620, 3981727096, 150775221, 3627908307, 1303187396, 508620638, 2975983352, 2726630617, 1817252668, 1876281319, 1457606340, 908771278, 3720792119, 3617206836, 2455994898, 1729034894, 1080033504];
private static const BLOCK_SIZE:uint = 8;
private static const P_SZ:uint = (ROUNDS + 2);
private static const SBOX_SK:uint = 0x0100;
public function BlowFishKey(key:ByteArray){
key = null;
super();
this.key = key;
setKey(key);
}
private function F(x:uint):uint{
return ((((S0[(x >>> 24)] + S1[((x >>> 16) & 0xFF)]) ^ S2[((x >>> 8) & 0xFF)]) + S3[(x & 0xFF)]));
}
private function BytesTo32bits(b:ByteArray, i:uint):uint{
return ((((((b[i] & 0xFF) << 24) | ((b[(i + 1)] & 0xFF) << 16)) | ((b[(i + 2)] & 0xFF) << 8)) | (b[(i + 3)] & 0xFF)));
}
public function decrypt(block:ByteArray, index:uint=0):void{
decryptBlock(block, index, block, index);
}
private function decryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint):void{
var xl:uint;
var xr:uint;
var i:uint;
xl = BytesTo32bits(src, srcIndex);
xr = BytesTo32bits(src, (srcIndex + 4));
xl = (xl ^ P[(ROUNDS + 1)]);
i = ROUNDS;
while (i > 0) {
xr = (xr ^ (F(xl) ^ P[i]));
xl = (xl ^ (F(xr) ^ P[(i - 1)]));
i = (i - 2);
};
xr = (xr ^ P[0]);
Bits32ToBytes(xr, dst, dstIndex);
Bits32ToBytes(xl, dst, (dstIndex + 4));
}
private function setKey(key:ByteArray):void{
var keyLength:uint;
var keyIndex:uint;
var i:uint;
var data:uint;
var j:uint;
S0 = KS0.concat();
S1 = KS1.concat();
S2 = KS2.concat();
S3 = KS3.concat();
P = KP.concat();
keyLength = key.length;
keyIndex = 0;
i = 0;
while (i < P_SZ) {
data = 0;
j = 0;
while (j < 4) {
var _temp1 = keyIndex;
keyIndex = (keyIndex + 1);
data = ((data << 8) | (key[_temp1] & 0xFF));
if (keyIndex >= keyLength){
keyIndex = 0;
};
j++;
};
P[i] = (P[i] ^ data);
i++;
};
processTable(0, 0, P);
processTable(P[(P_SZ - 2)], P[(P_SZ - 1)], S0);
processTable(S0[(SBOX_SK - 2)], S0[(SBOX_SK - 1)], S1);
processTable(S1[(SBOX_SK - 2)], S1[(SBOX_SK - 1)], S2);
processTable(S2[(SBOX_SK - 2)], S2[(SBOX_SK - 1)], S3);
}
public function dispose():void{
var i:uint;
i = 0;
i = 0;
while (i < S0.length) {
S0[i] = 0;
i++;
};
i = 0;
while (i < S1.length) {
S1[i] = 0;
i++;
};
i = 0;
while (i < S2.length) {
S2[i] = 0;
i++;
};
i = 0;
while (i < S3.length) {
S3[i] = 0;
i++;
};
i = 0;
while (i < P.length) {
P[i] = 0;
i++;
};
S0 = null;
S1 = null;
S2 = null;
S3 = null;
P = null;
i = 0;
while (i < key.length) {
key[i] = 0;
i++;
};
key.length = 0;
key = null;
Memory.gc();
}
private function encryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint):void{
var xl:uint;
var xr:uint;
var i:uint;
xl = BytesTo32bits(src, srcIndex);
xr = BytesTo32bits(src, (srcIndex + 4));
xl = (xl ^ P[0]);
i = 1;
while (i < ROUNDS) {
xr = (xr ^ (F(xl) ^ P[i]));
xl = (xl ^ (F(xr) ^ P[(i + 1)]));
i = (i + 2);
};
xr = (xr ^ P[(ROUNDS + 1)]);
Bits32ToBytes(xr, dst, dstIndex);
Bits32ToBytes(xl, dst, (dstIndex + 4));
}
public function encrypt(block:ByteArray, index:uint=0):void{
encryptBlock(block, index, block, index);
}
private function Bits32ToBytes(i:uint, b:ByteArray, offset:uint):void{
b[(offset + 3)] = i;
b[(offset + 2)] = (i >> 8);
b[(offset + 1)] = (i >> 16);
b[offset] = (i >> 24);
}
private function processTable(xl:uint, xr:uint, table:Array):void{
var size:uint;
var s:uint;
var i:uint;
size = table.length;
s = 0;
while (s < size) {
xl = (xl ^ P[0]);
i = 1;
while (i < ROUNDS) {
xr = (xr ^ (F(xl) ^ P[i]));
xl = (xl ^ (F(xr) ^ P[(i + 1)]));
i = (i + 2);
};
xr = (xr ^ P[(ROUNDS + 1)]);
table[s] = xr;
table[(s + 1)] = xl;
xr = xl;
xl = table[s];
s = (s + 2);
};
}
public function toString():String{
return ("blowfish");
}
public function getBlockSize():uint{
return (BLOCK_SIZE);
}
}
}//package com.hurlant.crypto.symmetric
Section 27
//CBCMode (com.hurlant.crypto.symmetric.CBCMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class CBCMode extends IVMode implements IMode {
public function CBCMode(key:ISymmetricKey, padding:IPad=null){
super(key, padding);
}
public function toString():String{
return ((key.toString() + "-cbc"));
}
public function decrypt(src:ByteArray):void{
var vector:ByteArray;
var tmp:ByteArray;
var i:uint;
var j:uint;
vector = getIV4d();
tmp = new ByteArray();
i = 0;
while (i < src.length) {
tmp.position = 0;
tmp.writeBytes(src, i, blockSize);
key.decrypt(src, i);
j = 0;
while (j < blockSize) {
src[(i + j)] = (src[(i + j)] ^ vector[j]);
j++;
};
vector.position = 0;
vector.writeBytes(tmp, 0, blockSize);
i = (i + blockSize);
};
padding.unpad(src);
}
public function encrypt(src:ByteArray):void{
var vector:ByteArray;
var i:uint;
var j:uint;
padding.pad(src);
vector = getIV4e();
i = 0;
while (i < src.length) {
j = 0;
while (j < blockSize) {
src[(i + j)] = (src[(i + j)] ^ vector[j]);
j++;
};
key.encrypt(src, i);
vector.position = 0;
vector.writeBytes(src, i, blockSize);
i = (i + blockSize);
};
}
}
}//package com.hurlant.crypto.symmetric
Section 28
//CFB8Mode (com.hurlant.crypto.symmetric.CFB8Mode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class CFB8Mode extends IVMode implements IMode {
public function CFB8Mode(key:ISymmetricKey, padding:IPad=null){
super(key, null);
}
public function toString():String{
return ((key.toString() + "-cfb8"));
}
public function decrypt(src:ByteArray):void{
var vector:ByteArray;
var tmp:ByteArray;
var i:uint;
var c:uint;
var j:uint;
vector = getIV4d();
tmp = new ByteArray();
i = 0;
while (i < src.length) {
c = src[i];
tmp.position = 0;
tmp.writeBytes(vector);
key.encrypt(vector);
src[i] = (src[i] ^ vector[0]);
j = 0;
while (j < (blockSize - 1)) {
vector[j] = tmp[(j + 1)];
j++;
};
vector[(blockSize - 1)] = c;
i++;
};
}
public function encrypt(src:ByteArray):void{
var vector:ByteArray;
var tmp:ByteArray;
var i:uint;
var j:uint;
vector = getIV4e();
tmp = new ByteArray();
i = 0;
while (i < src.length) {
tmp.position = 0;
tmp.writeBytes(vector);
key.encrypt(vector);
src[i] = (src[i] ^ vector[0]);
j = 0;
while (j < (blockSize - 1)) {
vector[j] = tmp[(j + 1)];
j++;
};
vector[(blockSize - 1)] = src[i];
i++;
};
}
}
}//package com.hurlant.crypto.symmetric
Section 29
//CFBMode (com.hurlant.crypto.symmetric.CFBMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class CFBMode extends IVMode implements IMode {
public function CFBMode(key:ISymmetricKey, padding:IPad=null){
super(key, null);
}
public function toString():String{
return ((key.toString() + "-cfb"));
}
public function decrypt(src:ByteArray):void{
var l:uint;
var vector:ByteArray;
var tmp:ByteArray;
var i:uint;
var chunk:uint;
var j:uint;
l = src.length;
vector = getIV4d();
tmp = new ByteArray();
i = 0;
while (i < src.length) {
key.encrypt(vector);
chunk = (((i + blockSize))<l) ? blockSize : (l - i);
tmp.position = 0;
tmp.writeBytes(src, i, chunk);
j = 0;
while (j < chunk) {
src[(i + j)] = (src[(i + j)] ^ vector[j]);
j++;
};
vector.position = 0;
vector.writeBytes(tmp);
i = (i + blockSize);
};
}
public function encrypt(src:ByteArray):void{
var l:uint;
var vector:ByteArray;
var i:uint;
var chunk:uint;
var j:uint;
l = src.length;
vector = getIV4e();
i = 0;
while (i < src.length) {
key.encrypt(vector);
chunk = (((i + blockSize))<l) ? blockSize : (l - i);
j = 0;
while (j < chunk) {
src[(i + j)] = (src[(i + j)] ^ vector[j]);
j++;
};
vector.position = 0;
vector.writeBytes(src, i, chunk);
i = (i + blockSize);
};
}
}
}//package com.hurlant.crypto.symmetric
Section 30
//CTRMode (com.hurlant.crypto.symmetric.CTRMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class CTRMode extends IVMode implements IMode {
public function CTRMode(key:ISymmetricKey, padding:IPad=null){
super(key, padding);
}
public function toString():String{
return ((key.toString() + "-ctr"));
}
private function core(src:ByteArray, iv:ByteArray):void{
var X:ByteArray;
var Xenc:ByteArray;
var i:uint;
var j:uint;
X = new ByteArray();
Xenc = new ByteArray();
X.writeBytes(iv);
i = 0;
while (i < src.length) {
Xenc.position = 0;
Xenc.writeBytes(X);
key.encrypt(Xenc);
j = 0;
while (j < blockSize) {
src[(i + j)] = (src[(i + j)] ^ Xenc[j]);
j++;
};
j = (blockSize - 1);
while (j >= 0) {
var _local7 = X;
var _local8 = j;
var _local9 = (_local7[_local8] + 1);
_local7[_local8] = _local9;
if (X[j] != 0){
break;
};
j--;
};
i = (i + blockSize);
};
}
public function decrypt(src:ByteArray):void{
var vector:ByteArray;
vector = getIV4d();
core(src, vector);
padding.unpad(src);
}
public function encrypt(src:ByteArray):void{
var vector:ByteArray;
padding.pad(src);
vector = getIV4e();
core(src, vector);
}
}
}//package com.hurlant.crypto.symmetric
Section 31
//DESKey (com.hurlant.crypto.symmetric.DESKey)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.util.*;
public class DESKey implements ISymmetricKey {
protected var encKey:Array;
protected var key:ByteArray;
protected var decKey:Array;
private static const SP8:Array = [268439616, 0x1000, 262144, 268701760, 268435456, 268439616, 64, 268435456, 262208, 268697600, 268701760, 266240, 268701696, 266304, 0x1000, 64, 268697600, 268435520, 268439552, 4160, 266240, 262208, 268697664, 268701696, 4160, 0, 0, 268697664, 268435520, 268439552, 266304, 262144, 266304, 262144, 268701696, 0x1000, 64, 268697664, 0x1000, 266304, 268439552, 64, 268435520, 268697600, 268697664, 268435456, 262144, 268439616, 0, 268701760, 262208, 268435520, 268697600, 268439552, 268439616, 0, 268701760, 266240, 266240, 4160, 4160, 262208, 268435456, 268701696];
private static const bytebit:Array = [128, 64, 32, 16, 8, 4, 2, 1];
private static const bigbyte:Array = [0x800000, 0x400000, 0x200000, 0x100000, 524288, 262144, 131072, 65536, 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100, 128, 64, 32, 16, 8, 4, 2, 1];
private static const pc1:Array = [56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3];
private static const pc2:Array = [13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31];
private static const Df_Key:Array = [1, 35, 69, 103, 137, 171, 205, 239, 254, 220, 186, 152, 118, 84, 50, 16, 137, 171, 205, 239, 1, 35, 69, 103];
private static const totrot:Array = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
private static const SP1:Array = [16843776, 0, 65536, 16843780, 16842756, 66564, 4, 65536, 0x0400, 16843776, 16843780, 0x0400, 16778244, 16842756, 16777216, 4, 0x0404, 16778240, 16778240, 66560, 66560, 16842752, 16842752, 16778244, 65540, 16777220, 16777220, 65540, 0, 0x0404, 66564, 16777216, 65536, 16843780, 4, 16842752, 16843776, 16777216, 16777216, 0x0400, 16842756, 65536, 66560, 16777220, 0x0400, 4, 16778244, 66564, 16843780, 65540, 16842752, 16778244, 16777220, 0x0404, 66564, 16843776, 0x0404, 16778240, 16778240, 0, 65540, 66560, 0, 16842756];
private static const SP2:Array = [2148565024, 2147516416, 0x8000, 1081376, 0x100000, 32, 2148532256, 2147516448, 2147483680, 2148565024, 2148564992, 2147483648, 2147516416, 0x100000, 32, 2148532256, 0x108000, 0x100020, 2147516448, 0, 2147483648, 0x8000, 1081376, 2148532224, 0x100020, 2147483680, 0, 0x108000, 32800, 2148564992, 2148532224, 32800, 0, 1081376, 2148532256, 0x100000, 2147516448, 2148532224, 2148564992, 0x8000, 2148532224, 2147516416, 32, 2148565024, 1081376, 32, 0x8000, 2147483648, 32800, 2148564992, 0x100000, 2147483680, 0x100020, 2147516448, 2147483680, 0x100020, 0x108000, 0, 2147516416, 32800, 2147483648, 2148532256, 2148565024, 0x108000];
private static const SP3:Array = [520, 134349312, 0, 134348808, 134218240, 0, 131592, 134218240, 131080, 134217736, 134217736, 131072, 134349320, 131080, 134348800, 520, 134217728, 8, 134349312, 0x0200, 131584, 134348800, 134348808, 131592, 134218248, 131584, 131072, 134218248, 8, 134349320, 0x0200, 134217728, 134349312, 134217728, 131080, 520, 131072, 134349312, 134218240, 0, 0x0200, 131080, 134349320, 134218240, 134217736, 0x0200, 0, 134348808, 134218248, 131072, 134217728, 134349320, 8, 131592, 131584, 134217736, 134348800, 134218248, 520, 134348800, 131592, 8, 134348808, 131584];
private static const SP4:Array = [8396801, 8321, 8321, 128, 8396928, 0x800081, 0x800001, 8193, 0, 0x802000, 0x802000, 8396929, 129, 0, 0x800080, 0x800001, 1, 0x2000, 0x800000, 8396801, 128, 0x800000, 8193, 8320, 0x800081, 1, 8320, 0x800080, 0x2000, 8396928, 8396929, 129, 0x800080, 0x800001, 0x802000, 8396929, 129, 0, 0, 0x802000, 8320, 0x800080, 0x800081, 1, 8396801, 8321, 8321, 128, 8396929, 129, 1, 0x2000, 0x800001, 8193, 8396928, 0x800081, 8193, 8320, 0x800000, 8396801, 128, 0x800000, 0x2000, 8396928];
private static const SP5:Array = [0x0100, 34078976, 34078720, 1107296512, 524288, 0x0100, 1073741824, 34078720, 1074266368, 524288, 33554688, 1074266368, 1107296512, 1107820544, 524544, 1073741824, 33554432, 1074266112, 1074266112, 0, 1073742080, 1107820800, 1107820800, 33554688, 1107820544, 1073742080, 0, 1107296256, 34078976, 33554432, 1107296256, 524544, 524288, 1107296512, 0x0100, 33554432, 1073741824, 34078720, 1107296512, 1074266368, 33554688, 1073741824, 1107820544, 34078976, 1074266368, 0x0100, 33554432, 1107820544, 1107820800, 524544, 1107296256, 1107820800, 34078720, 0, 1074266112, 1107296256, 524544, 33554688, 1073742080, 524288, 0, 1074266112, 34078976, 1073742080];
private static const SP6:Array = [536870928, 541065216, 0x4000, 541081616, 541065216, 16, 541081616, 0x400000, 536887296, 4210704, 0x400000, 536870928, 0x400010, 536887296, 536870912, 16400, 0, 0x400010, 536887312, 0x4000, 0x404000, 536887312, 16, 541065232, 541065232, 0, 4210704, 541081600, 16400, 0x404000, 541081600, 536870912, 536887296, 16, 541065232, 0x404000, 541081616, 0x400000, 16400, 536870928, 0x400000, 536887296, 536870912, 16400, 536870928, 541081616, 0x404000, 541065216, 4210704, 541081600, 0, 541065232, 16, 0x4000, 541065216, 4210704, 0x4000, 0x400010, 536887312, 0, 541081600, 536870912, 0x400010, 536887312];
private static const SP7:Array = [0x200000, 69206018, 67110914, 0, 0x0800, 67110914, 2099202, 69208064, 69208066, 0x200000, 0, 67108866, 2, 67108864, 69206018, 2050, 67110912, 2099202, 0x200002, 67110912, 67108866, 69206016, 69208064, 0x200002, 69206016, 0x0800, 2050, 69208066, 0x200800, 2, 67108864, 0x200800, 67108864, 0x200800, 0x200000, 67110914, 67110914, 69206018, 69206018, 2, 0x200002, 67108864, 67110912, 0x200000, 69208064, 2050, 2099202, 69208064, 2050, 67108866, 69208066, 69206016, 0x200800, 0, 2, 69208066, 0, 2099202, 69206016, 0x0800, 67108866, 67110912, 0x0800, 0x200002];
public function DESKey(key:ByteArray){
super();
this.key = key;
this.encKey = generateWorkingKey(true, key, 0);
this.decKey = generateWorkingKey(false, key, 0);
}
protected function generateWorkingKey(encrypting:Boolean, key:ByteArray, off:uint):Array{
var newKey:Array;
var pc1m:ByteArray;
var pcr:ByteArray;
var l:uint;
var j:uint;
var i:uint;
var m:uint;
var n:uint;
var i1:uint;
var i2:uint;
newKey = [];
pc1m = new ByteArray();
pcr = new ByteArray();
j = 0;
while (j < 56) {
l = pc1[j];
pc1m[j] = !(((key[(off + (l >>> 3))] & bytebit[(l & 7)]) == 0));
j++;
};
i = 0;
while (i < 16) {
if (encrypting){
m = (i << 1);
} else {
m = ((15 - i) << 1);
};
n = (m + 1);
newKey[m] = (newKey[n] = 0);
j = 0;
while (j < 28) {
l = (j + totrot[i]);
if (l < 28){
pcr[j] = pc1m[l];
} else {
pcr[j] = pc1m[(l - 28)];
};
j++;
};
j = 28;
while (j < 56) {
l = (j + totrot[i]);
if (l < 56){
pcr[j] = pc1m[l];
} else {
pcr[j] = pc1m[(l - 28)];
};
j++;
};
j = 0;
while (j < 24) {
if (pcr[pc2[j]]){
newKey[m] = (newKey[m] | bigbyte[j]);
};
if (pcr[pc2[(j + 24)]]){
newKey[n] = (newKey[n] | bigbyte[j]);
};
j++;
};
i++;
};
i = 0;
while (i != 32) {
i1 = newKey[i];
i2 = newKey[(i + 1)];
newKey[i] = (((((i1 & 0xFC0000) << 6) | ((i1 & 4032) << 10)) | ((i2 & 0xFC0000) >>> 10)) | ((i2 & 4032) >>> 6));
newKey[(i + 1)] = (((((i1 & 258048) << 12) | ((i1 & 63) << 16)) | ((i2 & 258048) >>> 4)) | (i2 & 63));
i = (i + 2);
};
return (newKey);
}
public function encrypt(block:ByteArray, index:uint=0):void{
desFunc(encKey, block, index, block, index);
}
public function decrypt(block:ByteArray, index:uint=0):void{
desFunc(decKey, block, index, block, index);
}
public function dispose():void{
var i:uint;
i = 0;
i = 0;
while (i < encKey.length) {
encKey[i] = 0;
i++;
};
i = 0;
while (i < decKey.length) {
decKey[i] = 0;
i++;
};
encKey = null;
decKey = null;
i = 0;
while (i < key.length) {
key[i] = 0;
i++;
};
key.length = 0;
key = null;
Memory.gc();
}
protected function desFunc(wKey:Array, inp:ByteArray, inOff:uint, out:ByteArray, outOff:uint):void{
var work:uint;
var right:uint;
var left:uint;
var round:uint;
var fval:uint;
left = ((inp[(inOff + 0)] & 0xFF) << 24);
left = (left | ((inp[(inOff + 1)] & 0xFF) << 16));
left = (left | ((inp[(inOff + 2)] & 0xFF) << 8));
left = (left | (inp[(inOff + 3)] & 0xFF));
right = ((inp[(inOff + 4)] & 0xFF) << 24);
right = (right | ((inp[(inOff + 5)] & 0xFF) << 16));
right = (right | ((inp[(inOff + 6)] & 0xFF) << 8));
right = (right | (inp[(inOff + 7)] & 0xFF));
work = (((left >>> 4) ^ right) & 252645135);
right = (right ^ work);
left = (left ^ (work << 4));
work = (((left >>> 16) ^ right) & 0xFFFF);
right = (right ^ work);
left = (left ^ (work << 16));
work = (((right >>> 2) ^ left) & 858993459);
left = (left ^ work);
right = (right ^ (work << 2));
work = (((right >>> 8) ^ left) & 0xFF00FF);
left = (left ^ work);
right = (right ^ (work << 8));
right = (((right << 1) | ((right >>> 31) & 1)) & 4294967295);
work = ((left ^ right) & 2863311530);
left = (left ^ work);
right = (right ^ work);
left = (((left << 1) | ((left >>> 31) & 1)) & 4294967295);
round = 0;
while (round < 8) {
work = ((right << 28) | (right >>> 4));
work = (work ^ wKey[((round * 4) + 0)]);
fval = SP7[(work & 63)];
fval = (fval | SP5[((work >>> 8) & 63)]);
fval = (fval | SP3[((work >>> 16) & 63)]);
fval = (fval | SP1[((work >>> 24) & 63)]);
work = (right ^ wKey[((round * 4) + 1)]);
fval = (fval | SP8[(work & 63)]);
fval = (fval | SP6[((work >>> 8) & 63)]);
fval = (fval | SP4[((work >>> 16) & 63)]);
fval = (fval | SP2[((work >>> 24) & 63)]);
left = (left ^ fval);
work = ((left << 28) | (left >>> 4));
work = (work ^ wKey[((round * 4) + 2)]);
fval = SP7[(work & 63)];
fval = (fval | SP5[((work >>> 8) & 63)]);
fval = (fval | SP3[((work >>> 16) & 63)]);
fval = (fval | SP1[((work >>> 24) & 63)]);
work = (left ^ wKey[((round * 4) + 3)]);
fval = (fval | SP8[(work & 63)]);
fval = (fval | SP6[((work >>> 8) & 63)]);
fval = (fval | SP4[((work >>> 16) & 63)]);
fval = (fval | SP2[((work >>> 24) & 63)]);
right = (right ^ fval);
round++;
};
right = ((right << 31) | (right >>> 1));
work = ((left ^ right) & 2863311530);
left = (left ^ work);
right = (right ^ work);
left = ((left << 31) | (left >>> 1));
work = (((left >>> 8) ^ right) & 0xFF00FF);
right = (right ^ work);
left = (left ^ (work << 8));
work = (((left >>> 2) ^ right) & 858993459);
right = (right ^ work);
left = (left ^ (work << 2));
work = (((right >>> 16) ^ left) & 0xFFFF);
left = (left ^ work);
right = (right ^ (work << 16));
work = (((right >>> 4) ^ left) & 252645135);
left = (left ^ work);
right = (right ^ (work << 4));
out[(outOff + 0)] = ((right >>> 24) & 0xFF);
out[(outOff + 1)] = ((right >>> 16) & 0xFF);
out[(outOff + 2)] = ((right >>> 8) & 0xFF);
out[(outOff + 3)] = (right & 0xFF);
out[(outOff + 4)] = ((left >>> 24) & 0xFF);
out[(outOff + 5)] = ((left >>> 16) & 0xFF);
out[(outOff + 6)] = ((left >>> 8) & 0xFF);
out[(outOff + 7)] = (left & 0xFF);
}
public function toString():String{
return ("des");
}
public function getBlockSize():uint{
return (8);
}
}
}//package com.hurlant.crypto.symmetric
Section 32
//ECBMode (com.hurlant.crypto.symmetric.ECBMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.util.*;
public class ECBMode implements IMode, ICipher {
private var key:ISymmetricKey;
private var padding:IPad;
public function ECBMode(key:ISymmetricKey, padding:IPad=null){
super();
this.key = key;
if (padding == null){
padding = new PKCS5(key.getBlockSize());
} else {
padding.setBlockSize(key.getBlockSize());
};
this.padding = padding;
}
public function encrypt(src:ByteArray):void{
var blockSize:uint;
var tmp:ByteArray;
var dst:ByteArray;
var i:uint;
padding.pad(src);
src.position = 0;
blockSize = key.getBlockSize();
tmp = new ByteArray();
dst = new ByteArray();
i = 0;
while (i < src.length) {
tmp.length = 0;
src.readBytes(tmp, 0, blockSize);
key.encrypt(tmp);
dst.writeBytes(tmp);
i = (i + blockSize);
};
src.length = 0;
src.writeBytes(dst);
}
public function decrypt(src:ByteArray):void{
var blockSize:uint;
var tmp:ByteArray;
var dst:ByteArray;
var i:uint;
src.position = 0;
blockSize = key.getBlockSize();
if ((src.length % blockSize) != 0){
throw (new Error(("ECB mode cipher length must be a multiple of blocksize " + blockSize)));
};
tmp = new ByteArray();
dst = new ByteArray();
i = 0;
while (i < src.length) {
tmp.length = 0;
src.readBytes(tmp, 0, blockSize);
key.decrypt(tmp);
dst.writeBytes(tmp);
i = (i + blockSize);
};
padding.unpad(dst);
src.length = 0;
src.writeBytes(dst);
}
public function dispose():void{
key.dispose();
key = null;
padding = null;
Memory.gc();
}
public function getBlockSize():uint{
return (key.getBlockSize());
}
public function toString():String{
return ((key.toString() + "-ecb"));
}
}
}//package com.hurlant.crypto.symmetric
Section 33
//ICipher (com.hurlant.crypto.symmetric.ICipher)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public interface ICipher {
function encrypt(C:\ws\Crypto;com\hurlant\crypto\symmetric;ICipher.as:ByteArray):void;
function dispose():void;
function getBlockSize():uint;
function toString():String;
function decrypt(C:\ws\Crypto;com\hurlant\crypto\symmetric;ICipher.as:ByteArray):void;
}
}//package com.hurlant.crypto.symmetric
Section 34
//IMode (com.hurlant.crypto.symmetric.IMode)
package com.hurlant.crypto.symmetric {
public interface IMode extends ICipher {
}
}//package com.hurlant.crypto.symmetric
Section 35
//IPad (com.hurlant.crypto.symmetric.IPad)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public interface IPad {
function pad(:ByteArray):void;
function unpad(:ByteArray):void;
function setBlockSize(:uint):void;
}
}//package com.hurlant.crypto.symmetric
Section 36
//IStreamCipher (com.hurlant.crypto.symmetric.IStreamCipher)
package com.hurlant.crypto.symmetric {
public interface IStreamCipher extends ICipher {
}
}//package com.hurlant.crypto.symmetric
Section 37
//ISymmetricKey (com.hurlant.crypto.symmetric.ISymmetricKey)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public interface ISymmetricKey {
function encrypt(_arg1:ByteArray, _arg2:uint=0):void;
function dispose():void;
function getBlockSize():uint;
function toString():String;
function decrypt(_arg1:ByteArray, _arg2:uint=0):void;
}
}//package com.hurlant.crypto.symmetric
Section 38
//IVMode (com.hurlant.crypto.symmetric.IVMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.crypto.prng.*;
import com.hurlant.util.*;
public class IVMode {
protected var lastIV:ByteArray;
protected var iv:ByteArray;
protected var blockSize:uint;
protected var padding:IPad;
protected var prng:Random;
protected var key:ISymmetricKey;
public function IVMode(key:ISymmetricKey, padding:IPad=null){
super();
this.key = key;
blockSize = key.getBlockSize();
if (padding == null){
padding = new PKCS5(blockSize);
} else {
padding.setBlockSize(blockSize);
};
this.padding = padding;
prng = new Random();
iv = null;
lastIV = new ByteArray();
}
public function set IV(value:ByteArray):void{
iv = value;
lastIV.length = 0;
lastIV.writeBytes(iv);
}
protected function getIV4d():ByteArray{
var vec:ByteArray;
vec = new ByteArray();
if (iv){
vec.writeBytes(iv);
} else {
throw (new Error("an IV must be set before calling decrypt()"));
};
return (vec);
}
protected function getIV4e():ByteArray{
var vec:ByteArray;
vec = new ByteArray();
if (iv){
vec.writeBytes(iv);
} else {
prng.nextBytes(vec, blockSize);
};
lastIV.length = 0;
lastIV.writeBytes(vec);
return (vec);
}
public function get IV():ByteArray{
return (lastIV);
}
public function dispose():void{
var i:uint;
if (iv != null){
i = 0;
while (i < iv.length) {
iv[i] = prng.nextByte();
i++;
};
iv.length = 0;
iv = null;
};
if (lastIV != null){
i = 0;
while (i < iv.length) {
lastIV[i] = prng.nextByte();
i++;
};
lastIV.length = 0;
lastIV = null;
};
key.dispose();
key = null;
padding = null;
prng.dispose();
prng = null;
Memory.gc();
}
public function getBlockSize():uint{
return (key.getBlockSize());
}
}
}//package com.hurlant.crypto.symmetric
Section 39
//NullPad (com.hurlant.crypto.symmetric.NullPad)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class NullPad implements IPad {
public function NullPad(){
super();
}
public function pad(a:ByteArray):void{
}
public function unpad(a:ByteArray):void{
}
public function setBlockSize(bs:uint):void{
}
}
}//package com.hurlant.crypto.symmetric
Section 40
//OFBMode (com.hurlant.crypto.symmetric.OFBMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class OFBMode extends IVMode implements IMode {
public function OFBMode(key:ISymmetricKey, padding:IPad=null){
super(key, null);
}
public function toString():String{
return ((key.toString() + "-ofb"));
}
private function core(src:ByteArray, iv:ByteArray):void{
var l:uint;
var tmp:ByteArray;
var i:uint;
var chunk:uint;
var j:uint;
l = src.length;
tmp = new ByteArray();
i = 0;
while (i < src.length) {
key.encrypt(iv);
tmp.position = 0;
tmp.writeBytes(iv);
chunk = (((i + blockSize))<l) ? blockSize : (l - i);
j = 0;
while (j < chunk) {
src[(i + j)] = (src[(i + j)] ^ iv[j]);
j++;
};
iv.position = 0;
iv.writeBytes(tmp);
i = (i + blockSize);
};
}
public function decrypt(src:ByteArray):void{
var vector:ByteArray;
vector = getIV4d();
core(src, vector);
}
public function encrypt(src:ByteArray):void{
var vector:ByteArray;
vector = getIV4e();
core(src, vector);
}
}
}//package com.hurlant.crypto.symmetric
Section 41
//PKCS5 (com.hurlant.crypto.symmetric.PKCS5)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
public class PKCS5 implements IPad {
private var blockSize:uint;
public function PKCS5(blockSize:uint=0){
super();
this.blockSize = blockSize;
}
public function unpad(a:ByteArray):void{
var c:uint;
var i:uint;
var v:uint;
c = (a.length % blockSize);
if (c != 0){
throw (new Error("PKCS#5::unpad: ByteArray.length isn't a multiple of the blockSize"));
};
c = a[(a.length - 1)];
i = c;
while (i > 0) {
v = a[(a.length - 1)];
a.length--;
if (c != v){
throw (new Error((((("PKCS#5:unpad: Invalid padding value. expected [" + c) + "], found [") + v) + "]")));
};
i--;
};
}
public function pad(a:ByteArray):void{
var c:uint;
var i:uint;
c = (blockSize - (a.length % blockSize));
i = 0;
while (i < c) {
a[a.length] = c;
i++;
};
}
public function setBlockSize(bs:uint):void{
blockSize = bs;
}
}
}//package com.hurlant.crypto.symmetric
Section 42
//SimpleIVMode (com.hurlant.crypto.symmetric.SimpleIVMode)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.util.*;
public class SimpleIVMode implements IMode, ICipher {
protected var mode:IVMode;
protected var cipher:ICipher;
public function SimpleIVMode(mode:IVMode){
super();
this.mode = mode;
cipher = (mode as ICipher);
}
public function encrypt(src:ByteArray):void{
var tmp:ByteArray;
cipher.encrypt(src);
tmp = new ByteArray();
tmp.writeBytes(mode.IV);
tmp.writeBytes(src);
src.position = 0;
src.writeBytes(tmp);
}
public function decrypt(src:ByteArray):void{
var tmp:ByteArray;
tmp = new ByteArray();
tmp.writeBytes(src, 0, getBlockSize());
mode.IV = tmp;
tmp = new ByteArray();
tmp.writeBytes(src, getBlockSize());
cipher.decrypt(tmp);
src.length = 0;
src.writeBytes(tmp);
}
public function dispose():void{
mode.dispose();
mode = null;
cipher = null;
Memory.gc();
}
public function toString():String{
return (("simple-" + cipher.toString()));
}
public function getBlockSize():uint{
return (mode.getBlockSize());
}
}
}//package com.hurlant.crypto.symmetric
Section 43
//TripleDESKey (com.hurlant.crypto.symmetric.TripleDESKey)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.util.*;
public class TripleDESKey extends DESKey {
protected var decKey2:Array;
protected var decKey3:Array;
protected var encKey2:Array;
protected var encKey3:Array;
public function TripleDESKey(key:ByteArray){
super(key);
encKey2 = generateWorkingKey(false, key, 8);
decKey2 = generateWorkingKey(true, key, 8);
if (key.length > 16){
encKey3 = generateWorkingKey(true, key, 16);
decKey3 = generateWorkingKey(false, key, 16);
} else {
encKey3 = encKey;
decKey3 = decKey;
};
}
override public function decrypt(block:ByteArray, index:uint=0):void{
desFunc(decKey3, block, index, block, index);
desFunc(decKey2, block, index, block, index);
desFunc(decKey, block, index, block, index);
}
override public function encrypt(block:ByteArray, index:uint=0):void{
desFunc(encKey, block, index, block, index);
desFunc(encKey2, block, index, block, index);
desFunc(encKey3, block, index, block, index);
}
override public function dispose():void{
var i:uint;
super.dispose();
i = 0;
if (encKey2 != null){
i = 0;
while (i < encKey2.length) {
encKey2[i] = 0;
i++;
};
encKey2 = null;
};
if (encKey3 != null){
i = 0;
while (i < encKey3.length) {
encKey3[i] = 0;
i++;
};
encKey3 = null;
};
if (decKey2 != null){
i = 0;
while (i < decKey2.length) {
decKey2[i] = 0;
i++;
};
decKey2 = null;
};
if (decKey3 != null){
i = 0;
while (i < decKey3.length) {
decKey3[i] = 0;
i++;
};
decKey3 = null;
};
Memory.gc();
}
override public function toString():String{
return ("3des");
}
}
}//package com.hurlant.crypto.symmetric
Section 44
//XTeaKey (com.hurlant.crypto.symmetric.XTeaKey)
package com.hurlant.crypto.symmetric {
import flash.utils.*;
import com.hurlant.crypto.prng.*;
import com.hurlant.util.*;
public class XTeaKey implements ISymmetricKey {
public const NUM_ROUNDS:uint = 64;
private var k:Array;
public function XTeaKey(a:ByteArray){
super();
a.position = 0;
k = [a.readUnsignedInt(), a.readUnsignedInt(), a.readUnsignedInt(), a.readUnsignedInt()];
}
public function dispose():void{
var r:Random;
var i:uint;
r = new Random();
i = 0;
while (i < k.length) {
k[i] = r.nextByte();
delete k[i];
i++;
};
k = null;
Memory.gc();
}
public function encrypt(block:ByteArray, index:uint=0):void{
var v0:uint;
var v1:uint;
var i:uint;
var sum:uint;
var delta:uint;
block.position = index;
v0 = block.readUnsignedInt();
v1 = block.readUnsignedInt();
sum = 0;
delta = 2654435769;
i = 0;
while (i < NUM_ROUNDS) {
v0 = (v0 + ((((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[(sum & 3)])));
sum = (sum + delta);
v1 = (v1 + ((((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[((sum >> 11) & 3)])));
i++;
};
block.position = (block.position - 8);
block.writeUnsignedInt(v0);
block.writeUnsignedInt(v1);
}
public function decrypt(block:ByteArray, index:uint=0):void{
var v0:uint;
var v1:uint;
var i:uint;
var delta:uint;
var sum:uint;
block.position = index;
v0 = block.readUnsignedInt();
v1 = block.readUnsignedInt();
delta = 2654435769;
sum = (delta * NUM_ROUNDS);
i = 0;
while (i < NUM_ROUNDS) {
v1 = (v1 - ((((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[((sum >> 11) & 3)])));
sum = (sum - delta);
v0 = (v0 - ((((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[(sum & 3)])));
i++;
};
block.position = (block.position - 8);
block.writeUnsignedInt(v0);
block.writeUnsignedInt(v1);
}
public function toString():String{
return ("xtea");
}
public function getBlockSize():uint{
return (8);
}
public static function parseKey(K:String):XTeaKey{
var a:ByteArray;
a = new ByteArray();
a.writeUnsignedInt(parseInt(K.substr(0, 8), 16));
a.writeUnsignedInt(parseInt(K.substr(8, 8), 16));
a.writeUnsignedInt(parseInt(K.substr(16, 8), 16));
a.writeUnsignedInt(parseInt(K.substr(24, 8), 16));
a.position = 0;
return (new XTeaKey(a));
}
}
}//package com.hurlant.crypto.symmetric
Section 45
//Crypto (com.hurlant.crypto.Crypto)
package com.hurlant.crypto {
import flash.utils.*;
import com.hurlant.crypto.symmetric.*;
import com.hurlant.crypto.hash.*;
import com.hurlant.crypto.rsa.*;
import com.hurlant.crypto.prng.*;
import com.hurlant.util.*;
public class Crypto {
private var b64:Base64;
public function Crypto(){
super();
}
public static function getCipher(name:String, key:ByteArray, pad:IPad=null):ICipher{
var keys:Array;
var _local5:ICipher;
keys = name.split("-");
switch (keys[0]){
case "simple":
keys.shift();
name = keys.join("-");
_local5 = getCipher(name, key, pad);
if ((_local5 is IVMode)){
return (new SimpleIVMode((_local5 as IVMode)));
};
return (_local5);
case "aes":
case "aes128":
case "aes192":
case "aes256":
keys.shift();
if ((key.length * 8) == keys[0]){
keys.shift();
};
return (getMode(keys[0], new AESKey(key), pad));
case "bf":
case "blowfish":
keys.shift();
return (getMode(keys[0], new BlowFishKey(key), pad));
case "des":
keys.shift();
if (((!((keys[0] == "ede"))) && (!((keys[0] == "ede3"))))){
return (getMode(keys[0], new DESKey(key), pad));
};
if (keys.length == 1){
keys.push("ecb");
};
case "3des":
case "des3":
keys.shift();
return (getMode(keys[0], new TripleDESKey(key), pad));
case "xtea":
keys.shift();
return (getMode(keys[0], new XTeaKey(key), pad));
case "rc4":
keys.shift();
return (new ARC4(key));
};
return (null);
}
public static function getHash(name:String):IHash{
switch (name){
case "md2":
return (new MD2());
case "md5":
return (new MD5());
case "sha":
case "sha1":
return (new SHA1());
case "sha224":
return (new SHA224());
case "sha256":
return (new SHA256());
};
return (null);
}
public static function getRSA(E:String, M:String):RSAKey{
return (RSAKey.parsePublicKey(M, E));
}
private static function getMode(name:String, alg:ISymmetricKey, padding:IPad=null):IMode{
switch (name){
case "ecb":
return (new ECBMode(alg, padding));
case "cfb":
return (new CFBMode(alg, padding));
case "cfb8":
return (new CFB8Mode(alg, padding));
case "ofb":
return (new OFBMode(alg, padding));
case "ctr":
return (new CTRMode(alg, padding));
case "cbc":
default:
return (new CBCMode(alg, padding));
};
}
public static function getKeySize(name:String):uint{
var keys:Array;
keys = name.split("-");
switch (keys[0]){
case "simple":
keys.shift();
return (getKeySize(keys.join("-")));
case "aes128":
return (16);
case "aes192":
return (24);
case "aes256":
return (32);
case "aes":
keys.shift();
return ((parseInt(keys[0]) / 8));
case "bf":
case "blowfish":
return (16);
case "des":
keys.shift();
switch (keys[0]){
case "ede":
return (16);
case "ede3":
return (24);
default:
return (8);
};
case "3des":
case "des3":
return (24);
case "xtea":
return (8);
case "rc4":
if (parseInt(keys[1]) > 0){
return ((parseInt(keys[1]) / 8));
};
return (16);
};
return (0);
}
public static function getPad(name:String):IPad{
switch (name){
case "null":
return (new NullPad());
case "pkcs5":
default:
return (new PKCS5());
};
}
public static function getHMAC(name:String):HMAC{
var keys:Array;
var bits:uint;
keys = name.split("-");
if (keys[0] == "hmac"){
keys.shift();
};
bits = 0;
if (keys.length > 1){
bits = parseInt(keys[1]);
};
return (new HMAC(getHash(keys[0]), bits));
}
}
}//package com.hurlant.crypto
Section 46
//BarrettReduction (com.hurlant.math.BarrettReduction)
package com.hurlant.math {
import com.hurlant.math.*;
class BarrettReduction implements IReduction {
private var r2:BigInteger;
private var q3:BigInteger;
private var mu:BigInteger;
private var m:BigInteger;
function BarrettReduction(m:BigInteger){
super();
r2 = new BigInteger();
q3 = new BigInteger();
BigInteger.ONE.dlShiftTo((2 * m.t), r2);
mu = r2.divide(m);
this.m = m;
}
public function reduce(lx:BigInteger):void{
var x:BigInteger;
x = (lx as BigInteger);
x.drShiftTo((m.t - 1), r2);
if (x.t > (m.t + 1)){
x.t = (m.t + 1);
x.clamp();
};
mu.multiplyUpperTo(r2, (m.t + 1), q3);
m.multiplyLowerTo(q3, (m.t + 1), r2);
while (x.compareTo(r2) < 0) {
x.dAddOffset(1, (m.t + 1));
};
x.subTo(r2, x);
while (x.compareTo(m) >= 0) {
x.subTo(m, x);
};
}
public function revert(x:BigInteger):BigInteger{
return (x);
}
public function convert(x:BigInteger):BigInteger{
var r:BigInteger;
if ((((x.s < 0)) || ((x.t > (2 * m.t))))){
return (x.mod(m));
};
if (x.compareTo(m) < 0){
return (x);
};
r = new BigInteger();
x.copyTo(r);
reduce(r);
return (r);
}
public function sqrTo(x:BigInteger, r:BigInteger):void{
x.squareTo(r);
reduce(r);
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void{
x.multiplyTo(y, r);
reduce(r);
}
}
}//package com.hurlant.math
Section 47
//bi_internal (com.hurlant.math.bi_internal)
package com.hurlant.math {
public namespace bi_internal = "http://crypto.hurlant.com/BigInteger";
}//package com.hurlant.math
Section 48
//BigInteger (com.hurlant.math.BigInteger)
package com.hurlant.math {
import flash.utils.*;
import com.hurlant.crypto.prng.*;
import com.hurlant.util.*;
public class BigInteger {
bi_internal var a:Array;
bi_internal var s:int;
public var t:int;
public static const ONE:BigInteger = nbv(1);
public static const ZERO:BigInteger = nbv(0);
public static const DM:int = (DV - 1);
public static const F1:int = 22;
public static const F2:int = 8;
public static const lplim:int = ((1 << 26) / lowprimes[(lowprimes.length - 1)]);
public static const lowprimes:Array = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 0x0101, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509];
public static const FV:Number = Math.pow(2, BI_FP);
public static const BI_FP:int = 52;
public static const DV:int = (1 << DB);
public static const DB:int = 30;
public function BigInteger(value=null, radix:int=0){
var array:ByteArray;
var length:int;
super();
a = new Array();
if ((value is String)){
value = Hex.toArray(value);
radix = 0;
};
if ((value is ByteArray)){
array = (value as ByteArray);
length = ((radix) || ((array.length - array.position)));
fromArray(array, length);
};
}
public function clearBit(n:int):BigInteger{
return (changeBit(n, op_andnot));
}
public function negate():BigInteger{
var r:BigInteger;
r = nbi();
ZERO.subTo(this, r);
return (r);
}
public function andNot(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
bitwiseTo(a, op_andnot, r);
return (r);
}
public function modPow(e:BigInteger, m:BigInteger):BigInteger{
var i:int;
var k:int;
var r:BigInteger;
var z:IReduction;
var g:Array;
var n:int;
var k1:int;
var km:int;
var j:int;
var w:int;
var is1:Boolean;
var r2:BigInteger;
var t:BigInteger;
var g2:BigInteger;
i = e.bitLength();
r = nbv(1);
if (i <= 0){
return (r);
};
if (i < 18){
k = 1;
} else {
if (i < 48){
k = 3;
} else {
if (i < 144){
k = 4;
} else {
if (i < 0x0300){
k = 5;
} else {
k = 6;
};
};
};
};
if (i < 8){
z = new ClassicReduction(m);
} else {
if (m.isEven()){
z = new BarrettReduction(m);
} else {
z = new MontgomeryReduction(m);
};
};
g = [];
n = 3;
k1 = (k - 1);
km = ((1 << k) - 1);
g[1] = z.convert(this);
if (k > 1){
g2 = new BigInteger();
z.sqrTo(g[1], g2);
while (n <= km) {
g[n] = new BigInteger();
z.mulTo(g2, g[(n - 2)], g[n]);
n = (n + 2);
};
};
j = (e.t - 1);
is1 = true;
r2 = new BigInteger();
i = (nbits(e.a[j]) - 1);
while (j >= 0) {
if (i >= k1){
w = ((e.a[j] >> (i - k1)) & km);
} else {
w = ((e.a[j] & ((1 << (i + 1)) - 1)) << (k1 - i));
if (j > 0){
w = (w | (e.a[(j - 1)] >> ((DB + i) - k1)));
};
};
n = k;
while ((w & 1) == 0) {
w = (w >> 1);
n--;
};
i = (i - n);
if (i < 0){
i = (i + DB);
j--;
};
if (is1){
g[w].copyTo(r);
is1 = false;
} else {
while (n > 1) {
z.sqrTo(r, r2);
z.sqrTo(r2, r);
n = (n - 2);
};
if (n > 0){
z.sqrTo(r, r2);
} else {
t = r;
r = r2;
r2 = t;
};
z.mulTo(r2, g[w], r);
};
while ((((j >= 0)) && (((e.a[j] & (1 << i)) == 0)))) {
z.sqrTo(r, r2);
t = r;
r = r2;
r2 = t;
--i;
if (i < 0){
i = (DB - 1);
j--;
};
};
};
return (z.revert(r));
}
public function isProbablePrime(t:int):Boolean{
var i:int;
var x:BigInteger;
var m:int;
var j:int;
x = abs();
if ((((x.t == 1)) && ((x.a[0] <= lowprimes[(lowprimes.length - 1)])))){
i = 0;
while (i < lowprimes.length) {
if (x[0] == lowprimes[i]){
return (true);
};
i++;
};
return (false);
};
if (x.isEven()){
return (false);
};
i = 1;
while (i < lowprimes.length) {
m = lowprimes[i];
j = (i + 1);
while ((((j < lowprimes.length)) && ((m < lplim)))) {
var _temp1 = j;
j = (j + 1);
m = (m * lowprimes[_temp1]);
};
m = x.modInt(m);
while (i < j) {
var _temp2 = m;
var _temp3 = i;
i = (i + 1);
if ((_temp2 % lowprimes[_temp3]) == 0){
return (false);
};
};
};
return (x.millerRabin(t));
}
private function op_or(x:int, y:int):int{
return ((x | y));
}
public function mod(v:BigInteger):BigInteger{
var r:BigInteger;
r = nbi();
abs().divRemTo(v, null, r);
if ((((s < 0)) && ((r.compareTo(ZERO) > 0)))){
v.subTo(r, r);
};
return (r);
}
protected function addTo(a:BigInteger, r:BigInteger):void{
var i:int;
var c:int;
var m:int;
i = 0;
c = 0;
m = Math.min(a.t, t);
while (i < m) {
c = (c + (this.a[i] + a.a[i]));
var _temp1 = i;
i = (i + 1);
var _local6 = _temp1;
r.a[_local6] = (c & DM);
c = (c >> DB);
};
if (a.t < t){
c = (c + a.s);
while (i < t) {
c = (c + this.a[i]);
var _temp2 = i;
i = (i + 1);
_local6 = _temp2;
r.a[_local6] = (c & DM);
c = (c >> DB);
};
c = (c + s);
} else {
c = (c + s);
while (i < a.t) {
c = (c + a.a[i]);
var _temp3 = i;
i = (i + 1);
_local6 = _temp3;
r.a[_local6] = (c & DM);
c = (c >> DB);
};
c = (c + a.s);
};
r.s = ((c)<0) ? -1 : 0;
if (c > 0){
var _temp4 = i;
i = (i + 1);
_local6 = _temp4;
r.a[_local6] = c;
} else {
if (c < -1){
var _temp5 = i;
i = (i + 1);
_local6 = _temp5;
r.a[_local6] = (DV + c);
};
};
r.t = i;
r.clamp();
}
protected function bitwiseTo(a:BigInteger, op:Function, r:BigInteger):void{
var i:int;
var f:int;
var m:int;
m = Math.min(a.t, t);
i = 0;
while (i < m) {
r.a[i] = op(this.a[i], a.a[i]);
i++;
};
if (a.t < t){
f = (a.s & DM);
i = m;
while (i < t) {
r.a[i] = op(this.a[i], f);
i++;
};
r.t = t;
} else {
f = (s & DM);
i = m;
while (i < a.t) {
r.a[i] = op(f, a.a[i]);
i++;
};
r.t = a.t;
};
r.s = op(s, a.s);
r.clamp();
}
protected function modInt(n:int):int{
var d:int;
var r:int;
var i:int;
if (n <= 0){
return (0);
};
d = (DV % n);
r = ((s)<0) ? (n - 1) : 0;
if (t > 0){
if (d == 0){
r = (a[0] % n);
} else {
i = (t - 1);
while (i >= 0) {
r = (((d * r) + a[i]) % n);
i--;
};
};
};
return (r);
}
protected function chunkSize(r:Number):int{
return (Math.floor(((Math.LN2 * DB) / Math.log(r))));
}
bi_internal function dAddOffset(n:int, w:int):void{
while (t <= w) {
var _local3 = t++;
a[_local3] = 0;
};
a[w] = (a[w] + n);
while (a[w] >= DV) {
a[w] = (a[w] - DV);
++w;
if (w >= t){
_local3 = t++;
a[_local3] = 0;
};
_local3 = a;
var _local4 = w;
var _local5 = (_local3[_local4] + 1);
_local3[_local4] = _local5;
};
}
bi_internal function lShiftTo(n:int, r:BigInteger):void{
var bs:int;
var cbs:int;
var bm:int;
var ds:int;
var c:int;
var i:int;
bs = (n % DB);
cbs = (DB - bs);
bm = ((1 << cbs) - 1);
ds = (n / DB);
c = ((s << bs) & DM);
i = (t - 1);
while (i >= 0) {
r.a[((i + ds) + 1)] = ((a[i] >> cbs) | c);
c = ((a[i] & bm) << bs);
i--;
};
i = (ds - 1);
while (i >= 0) {
r.a[i] = 0;
i--;
};
r.a[ds] = c;
r.t = ((t + ds) + 1);
r.s = s;
r.clamp();
}
public function getLowestSetBit():int{
var i:int;
i = 0;
while (i < t) {
if (a[i] != 0){
return (((i * DB) + lbit(a[i])));
};
i++;
};
if (s < 0){
return ((t * DB));
};
return (-1);
}
public function subtract(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
subTo(a, r);
return (r);
}
public function primify(bits:int, t:int):void{
if (!testBit((bits - 1))){
bitwiseTo(BigInteger.ONE.shiftLeft((bits - 1)), op_or, this);
};
if (isEven()){
dAddOffset(1, 0);
};
while (!(isProbablePrime(t))) {
dAddOffset(2, 0);
while (bitLength() > bits) {
subTo(BigInteger.ONE.shiftLeft((bits - 1)), this);
};
};
}
public function gcd(a:BigInteger):BigInteger{
var x:BigInteger;
var y:BigInteger;
var i:int;
var g:int;
var t:BigInteger;
x = ((s)<0) ? negate() : clone();
y = ((a.s)<0) ? a.negate() : a.clone();
if (x.compareTo(y) < 0){
t = x;
x = y;
y = t;
};
i = x.getLowestSetBit();
g = y.getLowestSetBit();
if (g < 0){
return (x);
};
if (i < g){
g = i;
};
if (g > 0){
x.rShiftTo(g, x);
y.rShiftTo(g, y);
};
while (x.sigNum() > 0) {
i = x.getLowestSetBit();
if (i > 0){
x.rShiftTo(i, x);
};
i = y.getLowestSetBit();
if (i > 0){
y.rShiftTo(i, y);
};
if (x.compareTo(y) >= 0){
x.subTo(y, x);
x.rShiftTo(1, x);
} else {
y.subTo(x, y);
y.rShiftTo(1, y);
};
};
if (g > 0){
y.lShiftTo(g, y);
};
return (y);
}
bi_internal function multiplyLowerTo(a:BigInteger, n:int, r:BigInteger):void{
var i:int;
var j:int;
i = Math.min((t + a.t), n);
r.s = 0;
r.t = i;
while (i > 0) {
--i;
var _local6 = i;
r.a[_local6] = 0;
};
j = (r.t - t);
while (i < j) {
r.a[(i + t)] = am(0, a.a[i], r, i, 0, t);
i++;
};
j = Math.min(a.t, n);
while (i < j) {
am(0, a.a[i], r, i, 0, (n - i));
i++;
};
r.clamp();
}
public function modPowInt(e:int, m:BigInteger):BigInteger{
var z:IReduction;
if ((((e < 0x0100)) || (m.isEven()))){
z = new ClassicReduction(m);
} else {
z = new MontgomeryReduction(m);
};
return (exp(e, z));
}
bi_internal function intAt(str:String, index:int):int{
return (parseInt(str.charAt(index), 36));
}
public function testBit(n:int):Boolean{
var j:int;
j = Math.floor((n / DB));
if (j >= t){
return (!((s == 0)));
};
return (!(((a[j] & (1 << (n % DB))) == 0)));
}
bi_internal function exp(e:int, z:IReduction):BigInteger{
var r:BigInteger;
var r2:BigInteger;
var g:BigInteger;
var i:int;
var t:BigInteger;
if ((((e > 4294967295)) || ((e < 1)))){
return (ONE);
};
r = nbi();
r2 = nbi();
g = z.convert(this);
i = (nbits(e) - 1);
g.copyTo(r);
while (--i >= 0) {
z.sqrTo(r, r2);
if ((e & (1 << i)) > 0){
z.mulTo(r2, g, r);
} else {
t = r;
r = r2;
r2 = t;
};
};
return (z.revert(r));
}
public function toArray(array:ByteArray):uint{
var k:int;
var km:int;
var d:int;
var i:int;
var p:int;
var m:Boolean;
var c:int;
k = 8;
km = ((1 << 8) - 1);
d = 0;
i = t;
p = (DB - ((i * DB) % k));
m = false;
c = 0;
var _temp1 = i;
i = (i - 1);
if (_temp1 > 0){
if ((((p < DB)) && (((a[i] >> p) > 0)))){
m = true;
array.writeByte(d);
c++;
};
while (i >= 0) {
if (p < k){
d = ((a[i] & ((1 << p) - 1)) << (k - p));
var _temp2 = d;
i = (i - 1);
p = (p + (DB - k));
d = (_temp2 | (a[i] >> p));
} else {
p = (p - k);
d = ((a[i] >> p) & km);
if (p <= 0){
p = (p + DB);
i--;
};
};
if (d > 0){
m = true;
};
if (m){
array.writeByte(d);
c++;
};
};
};
return (c);
}
public function dispose():void{
var r:Random;
var i:uint;
r = new Random();
i = 0;
while (i < a.length) {
a[i] = r.nextByte();
delete a[i];
i++;
};
a = null;
t = 0;
s = 0;
Memory.gc();
}
private function lbit(x:int):int{
var r:int;
if (x == 0){
return (-1);
};
r = 0;
if ((x & 0xFFFF) == 0){
x = (x >> 16);
r = (r + 16);
};
if ((x & 0xFF) == 0){
x = (x >> 8);
r = (r + 8);
};
if ((x & 15) == 0){
x = (x >> 4);
r = (r + 4);
};
if ((x & 3) == 0){
x = (x >> 2);
r = (r + 2);
};
if ((x & 1) == 0){
r++;
};
return (r);
}
bi_internal function divRemTo(m:BigInteger, q:BigInteger=null, r:BigInteger=null):void{
var pm:BigInteger;
var pt:BigInteger;
var y:BigInteger;
var ts:int;
var ms:int;
var nsh:int;
var ys:int;
var y0:int;
var yt:Number;
var d1:Number;
var d2:Number;
var e:Number;
var i:int;
var j:int;
var t:BigInteger;
var qd:int;
var m = m;
var q = q;
var r = r;
pm = m.abs();
if (pm.t <= 0){
return;
};
pt = abs();
if (pt.t < pm.t){
if (q != null){
q.fromInt(0);
};
if (r != null){
copyTo(r);
};
return;
};
if (r == null){
r = nbi();
};
y = nbi();
ts = s;
ms = m.s;
nsh = (DB - nbits(pm.a[(pm.t - 1)]));
if (nsh > 0){
pm.lShiftTo(nsh, y);
pt.lShiftTo(nsh, r);
} else {
pm.copyTo(y);
pt.copyTo(r);
};
ys = y.t;
y0 = y.a[(ys - 1)];
if (y0 == 0){
return;
};
yt = ((y0 * (1 << F1)) + ((ys)>1) ? (y.a[(ys - 2)] >> F2) : 0);
d1 = (FV / yt);
d2 = ((1 << F1) / yt);
e = (1 << F2);
i = r.t;
j = (i - ys);
t = ((q)==null) ? nbi() : q;
y.dlShiftTo(j, t);
if (r.compareTo(t) >= 0){
var _local5 = r.t++;
r.a[_local5] = 1;
r.subTo(t, r);
};
ONE.dlShiftTo(ys, t);
t.subTo(y, y);
while (y.t < ys) {
y.(y.t++); //not popped
};
while ((j = (j - 1)), (j - 1) >= 0) {
i = (i - 1);
qd = ((r.a[(i - 1)])==y0) ? DM : ((Number(r.a[i]) * d1) + ((Number(r.a[(i - 1)]) + e) * d2));
if ((r.a[i] = (r.a[i] + y.am(0, qd, r, j, 0, ys))) < qd){
y.dlShiftTo(j, t);
r.subTo(t, r);
while ((qd = (qd - 1)), r.a[i] < (qd - 1)) {
r.subTo(t, r);
};
};
};
if (q != null){
r.drShiftTo(ys, q);
if (ts != ms){
ZERO.subTo(q, q);
};
};
r.t = ys;
r.clamp();
if (nsh > 0){
r.rShiftTo(nsh, r);
};
if (ts < 0){
ZERO.subTo(r, r);
};
}
public function remainder(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
divRemTo(a, null, r);
return (r);
}
public function divide(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
divRemTo(a, r, null);
return (r);
}
public function divideAndRemainder(a:BigInteger):Array{
var q:BigInteger;
var r:BigInteger;
q = new BigInteger();
r = new BigInteger();
divRemTo(a, q, r);
return ([q, r]);
}
public function valueOf():Number{
var coef:Number;
var value:Number;
var i:uint;
coef = 1;
value = 0;
i = 0;
while (i < t) {
value = (value + (a[i] * coef));
coef = (coef * DV);
i++;
};
return (value);
}
public function shiftLeft(n:int):BigInteger{
var r:BigInteger;
r = new BigInteger();
if (n < 0){
rShiftTo(-(n), r);
} else {
lShiftTo(n, r);
};
return (r);
}
public function multiply(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
multiplyTo(a, r);
return (r);
}
bi_internal function am(i:int, x:int, w:BigInteger, j:int, c:int, n:int):int{
var xl:int;
var xh:int;
var l:int;
var h:int;
var m:int;
xl = (x & 32767);
xh = (x >> 15);
while (--n >= 0) {
l = (a[i] & 32767);
var _temp1 = i;
i = (i + 1);
h = (a[_temp1] >> 15);
m = ((xh * l) + (h * xl));
l = ((((xl * l) + ((m & 32767) << 15)) + w.a[j]) + (c & 1073741823));
c = ((((l >>> 30) + (m >>> 15)) + (xh * h)) + (c >>> 30));
var _temp2 = j;
j = (j + 1);
var _local12 = _temp2;
w.a[_local12] = (l & 1073741823);
};
return (c);
}
bi_internal function drShiftTo(n:int, r:BigInteger):void{
var i:int;
i = n;
while (i < t) {
r.a[(i - n)] = a[i];
i++;
};
r.t = Math.max((t - n), 0);
r.s = s;
}
public function add(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
addTo(a, r);
return (r);
}
bi_internal function multiplyUpperTo(a:BigInteger, n:int, r:BigInteger):void{
var i:int;
n--;
i = (r.t = ((t + a.t) - n));
r.s = 0;
while (--i >= 0) {
r.a[i] = 0;
};
i = Math.max((n - t), 0);
while (i < a.t) {
r.a[((t + i) - n)] = am((n - i), a.a[i], r, 0, 0, ((t + i) - n));
i++;
};
r.clamp();
r.drShiftTo(1, r);
}
protected function nbi(){
return (new BigInteger());
}
protected function millerRabin(t:int):Boolean{
var n1:BigInteger;
var k:int;
var r:BigInteger;
var a:BigInteger;
var i:int;
var y:BigInteger;
var j:int;
n1 = subtract(BigInteger.ONE);
k = n1.getLowestSetBit();
if (k <= 0){
return (false);
};
r = n1.shiftRight(k);
t = ((t + 1) >> 1);
if (t > lowprimes.length){
t = lowprimes.length;
};
a = new BigInteger();
i = 0;
while (i < t) {
a.fromInt(lowprimes[i]);
y = a.modPow(r, this);
if (((!((y.compareTo(BigInteger.ONE) == 0))) && (!((y.compareTo(n1) == 0))))){
j = 1;
while ((((j++ < k)) && (!((y.compareTo(n1) == 0))))) {
y = y.modPowInt(2, this);
if (y.compareTo(BigInteger.ONE) == 0){
return (false);
};
};
if (y.compareTo(n1) != 0){
return (false);
};
};
i++;
};
return (true);
}
bi_internal function dMultiply(n:int):void{
a[t] = am(0, (n - 1), this, 0, 0, t);
t++;
clamp();
}
private function op_andnot(x:int, y:int):int{
return ((x & ~(y)));
}
bi_internal function clamp():void{
var c:int;
c = (s & DM);
while ((((t > 0)) && ((a[(t - 1)] == c)))) {
t--;
};
}
bi_internal function invDigit():int{
var x:int;
var y:int;
if (t < 1){
return (0);
};
x = a[0];
if ((x & 1) == 0){
return (0);
};
y = (x & 3);
y = ((y * (2 - ((x & 15) * y))) & 15);
y = ((y * (2 - ((x & 0xFF) * y))) & 0xFF);
y = ((y * (2 - (((x & 0xFFFF) * y) & 0xFFFF))) & 0xFFFF);
y = ((y * (2 - ((x * y) % DV))) % DV);
return (((y)>0) ? (DV - y) : -(y));
}
protected function changeBit(n:int, op:Function):BigInteger{
var r:BigInteger;
r = BigInteger.ONE.shiftLeft(n);
bitwiseTo(r, op, r);
return (r);
}
public function equals(a:BigInteger):Boolean{
return ((compareTo(a) == 0));
}
public function compareTo(v:BigInteger):int{
var r:int;
var i:int;
r = (s - v.s);
if (r != 0){
return (r);
};
i = t;
r = (i - v.t);
if (r != 0){
return (r);
};
while (--i >= 0) {
r = (a[i] - v.a[i]);
if (r != 0){
return (r);
};
};
return (0);
}
public function shiftRight(n:int):BigInteger{
var r:BigInteger;
r = new BigInteger();
if (n < 0){
lShiftTo(-(n), r);
} else {
rShiftTo(n, r);
};
return (r);
}
bi_internal function multiplyTo(v:BigInteger, r:BigInteger):void{
var x:BigInteger;
var y:BigInteger;
var i:int;
x = abs();
y = v.abs();
i = x.t;
r.t = (i + y.t);
while (--i >= 0) {
r.a[i] = 0;
};
i = 0;
while (i < y.t) {
r.a[(i + x.t)] = x.am(0, y.a[i], r, i, 0, x.t);
i++;
};
r.s = 0;
r.clamp();
if (s != v.s){
ZERO.subTo(r, r);
};
}
public function bitCount():int{
var r:int;
var x:int;
var i:int;
r = 0;
x = (s & DM);
i = 0;
while (i < t) {
r = (r + cbit((a[i] ^ x)));
i++;
};
return (r);
}
public function byteValue():int{
return (((t)==0) ? s : ((a[0] << 24) >> 24));
}
private function cbit(x:int):int{
var r:uint;
r = 0;
while (x != 0) {
x = (x & (x - 1));
r++;
};
return (r);
}
bi_internal function rShiftTo(n:int, r:BigInteger):void{
var ds:int;
var bs:int;
var cbs:int;
var bm:int;
var i:int;
r.s = s;
ds = (n / DB);
if (ds >= t){
r.t = 0;
return;
};
bs = (n % DB);
cbs = (DB - bs);
bm = ((1 << bs) - 1);
r.a[0] = (a[ds] >> bs);
i = (ds + 1);
while (i < t) {
r.a[((i - ds) - 1)] = (r.a[((i - ds) - 1)] | ((a[i] & bm) << cbs));
r.a[(i - ds)] = (a[i] >> bs);
i++;
};
if (bs > 0){
r.a[((t - ds) - 1)] = (r.a[((t - ds) - 1)] | ((s & bm) << cbs));
};
r.t = (t - ds);
r.clamp();
}
public function modInverse(m:BigInteger):BigInteger{
var ac:Boolean;
var u:BigInteger;
var v:BigInteger;
var a:BigInteger;
var b:BigInteger;
var c:BigInteger;
var d:BigInteger;
ac = m.isEven();
if (((((isEven()) && (ac))) || ((m.sigNum() == 0)))){
return (BigInteger.ZERO);
};
u = m.clone();
v = clone();
a = nbv(1);
b = nbv(0);
c = nbv(0);
d = nbv(1);
while (u.sigNum() != 0) {
while (u.isEven()) {
u.rShiftTo(1, u);
if (ac){
if (((!(a.isEven())) || (!(b.isEven())))){
a.addTo(this, a);
b.subTo(m, b);
};
a.rShiftTo(1, a);
} else {
if (!b.isEven()){
b.subTo(m, b);
};
};
b.rShiftTo(1, b);
};
while (v.isEven()) {
v.rShiftTo(1, v);
if (ac){
if (((!(c.isEven())) || (!(d.isEven())))){
c.addTo(this, c);
d.subTo(m, d);
};
c.rShiftTo(1, c);
} else {
if (!d.isEven()){
d.subTo(m, d);
};
};
d.rShiftTo(1, d);
};
if (u.compareTo(v) >= 0){
u.subTo(v, u);
if (ac){
a.subTo(c, a);
};
b.subTo(d, b);
} else {
v.subTo(u, v);
if (ac){
c.subTo(a, c);
};
d.subTo(b, d);
};
};
if (v.compareTo(BigInteger.ONE) != 0){
return (BigInteger.ZERO);
};
if (d.compareTo(m) >= 0){
return (d.subtract(m));
};
if (d.sigNum() < 0){
d.addTo(m, d);
} else {
return (d);
};
if (d.sigNum() < 0){
return (d.add(m));
};
return (d);
}
bi_internal function fromArray(value:ByteArray, length:int):void{
var p:int;
var i:int;
var sh:int;
var k:int;
var x:int;
p = value.position;
i = (p + length);
sh = 0;
k = 8;
t = 0;
s = 0;
while (--i >= p) {
x = ((i < value.length)) ? value[i] : 0;
if (sh == 0){
var _local8 = t++;
a[_local8] = x;
} else {
if ((sh + k) > DB){
a[(t - 1)] = (a[(t - 1)] | ((x & ((1 << (DB - sh)) - 1)) << sh));
_local8 = t++;
a[_local8] = (x >> (DB - sh));
} else {
a[(t - 1)] = (a[(t - 1)] | (x << sh));
};
};
sh = (sh + k);
if (sh >= DB){
sh = (sh - DB);
};
};
clamp();
value.position = Math.min((p + length), value.length);
}
bi_internal function copyTo(r:BigInteger):void{
var i:int;
i = (t - 1);
while (i >= 0) {
r.a[i] = a[i];
i--;
};
r.t = t;
r.s = s;
}
public function intValue():int{
if (s < 0){
if (t == 1){
return ((a[0] - DV));
};
if (t == 0){
return (-1);
};
} else {
if (t == 1){
return (a[0]);
};
if (t == 0){
return (0);
};
};
return ((((a[1] & ((1 << (32 - DB)) - 1)) << DB) | a[0]));
}
public function min(a:BigInteger):BigInteger{
return (((compareTo(a))<0) ? this : a);
}
public function bitLength():int{
if (t <= 0){
return (0);
};
return (((DB * (t - 1)) + nbits((a[(t - 1)] ^ (s & DM)))));
}
public function shortValue():int{
return (((t)==0) ? s : ((a[0] << 16) >> 16));
}
public function and(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
bitwiseTo(a, op_and, r);
return (r);
}
protected function toRadix(b:uint=10):String{
var cs:int;
var a:Number;
var d:BigInteger;
var y:BigInteger;
var z:BigInteger;
var r:String;
if ((((((sigNum() == 0)) || ((b < 2)))) || ((b > 32)))){
return ("0");
};
cs = chunkSize(b);
a = Math.pow(b, cs);
d = nbv(a);
y = nbi();
z = nbi();
r = "";
divRemTo(d, y, z);
while (y.sigNum() > 0) {
r = ((a + z.intValue()).toString(b).substr(1) + r);
y.divRemTo(d, y, z);
};
return ((z.intValue().toString(b) + r));
}
public function not():BigInteger{
var r:BigInteger;
var i:int;
r = new BigInteger();
i = 0;
while (i < t) {
r[i] = (DM & ~(a[i]));
i++;
};
r.t = t;
r.s = ~(s);
return (r);
}
bi_internal function subTo(v:BigInteger, r:BigInteger):void{
var i:int;
var c:int;
var m:int;
i = 0;
c = 0;
m = Math.min(v.t, t);
while (i < m) {
c = (c + (a[i] - v.a[i]));
var _temp1 = i;
i = (i + 1);
var _local6 = _temp1;
r.a[_local6] = (c & DM);
c = (c >> DB);
};
if (v.t < t){
c = (c - v.s);
while (i < t) {
c = (c + a[i]);
var _temp2 = i;
i = (i + 1);
_local6 = _temp2;
r.a[_local6] = (c & DM);
c = (c >> DB);
};
c = (c + s);
} else {
c = (c + s);
while (i < v.t) {
c = (c - v.a[i]);
var _temp3 = i;
i = (i + 1);
_local6 = _temp3;
r.a[_local6] = (c & DM);
c = (c >> DB);
};
c = (c - v.s);
};
r.s = ((c)<0) ? -1 : 0;
if (c < -1){
var _temp4 = i;
i = (i + 1);
_local6 = _temp4;
r.a[_local6] = (DV + c);
} else {
if (c > 0){
var _temp5 = i;
i = (i + 1);
_local6 = _temp5;
r.a[_local6] = c;
};
};
r.t = i;
r.clamp();
}
public function clone():BigInteger{
var r:BigInteger;
r = new BigInteger();
this.copyTo(r);
return (r);
}
public function pow(e:int):BigInteger{
return (exp(e, new NullReduction()));
}
public function flipBit(n:int):BigInteger{
return (changeBit(n, op_xor));
}
public function xor(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
bitwiseTo(a, op_xor, r);
return (r);
}
public function or(a:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
bitwiseTo(a, op_or, r);
return (r);
}
public function max(a:BigInteger):BigInteger{
return (((compareTo(a))>0) ? this : a);
}
bi_internal function fromInt(value:int):void{
t = 1;
s = ((value)<0) ? -1 : 0;
if (value > 0){
a[0] = value;
} else {
if (value < -1){
a[0] = (value + DV);
} else {
t = 0;
};
};
}
bi_internal function isEven():Boolean{
return ((((t)>0) ? (a[0] & 1) : s == 0));
}
public function toString(radix:Number=16):String{
var k:int;
var km:int;
var d:int;
var m:Boolean;
var r:String;
var i:int;
var p:int;
if (s < 0){
return (("-" + negate().toString(radix)));
};
switch (radix){
case 2:
k = 1;
break;
case 4:
k = 2;
break;
case 8:
k = 3;
break;
case 16:
k = 4;
break;
case 32:
k = 5;
break;
};
km = ((1 << k) - 1);
d = 0;
m = false;
r = "";
i = t;
p = (DB - ((i * DB) % k));
var _temp1 = i;
i = (i - 1);
if (_temp1 > 0){
if ((((p < DB)) && (((a[i] >> p) > 0)))){
m = true;
r = d.toString(36);
};
while (i >= 0) {
if (p < k){
d = ((a[i] & ((1 << p) - 1)) << (k - p));
var _temp2 = d;
i = (i - 1);
p = (p + (DB - k));
d = (_temp2 | (a[i] >> p));
} else {
p = (p - k);
d = ((a[i] >> p) & km);
if (p <= 0){
p = (p + DB);
i--;
};
};
if (d > 0){
m = true;
};
if (m){
r = (r + d.toString(36));
};
};
};
return ((m) ? r : "0");
}
public function setBit(n:int):BigInteger{
return (changeBit(n, op_or));
}
public function abs():BigInteger{
return (((s)<0) ? negate() : this);
}
bi_internal function nbits(x:int):int{
var r:int;
var t:int;
r = 1;
t = (x >>> 16);
if (t != 0){
x = t;
r = (r + 16);
};
t = (x >> 8);
if (t != 0){
x = t;
r = (r + 8);
};
t = (x >> 4);
if (t != 0){
x = t;
r = (r + 4);
};
t = (x >> 2);
if (t != 0){
x = t;
r = (r + 2);
};
t = (x >> 1);
if (t != 0){
x = t;
r = (r + 1);
};
return (r);
}
public function sigNum():int{
if (s < 0){
return (-1);
};
if ((((t <= 0)) || ((((t == 1)) && ((a[0] <= 0)))))){
return (0);
};
return (1);
}
public function toByteArray():ByteArray{
var i:int;
var r:ByteArray;
var p:int;
var d:int;
var k:int;
i = t;
r = new ByteArray();
r[0] = s;
p = (DB - ((i * DB) % 8));
k = 0;
var _temp1 = i;
i = (i - 1);
if (_temp1 > 0){
if ((((p < DB)) && (!(((a[i] >> p) == ((s & DM) >> p)))))){
var _temp2 = k;
k = (k + 1);
var _local6 = _temp2;
r[_local6] = (d | (s << (DB - p)));
};
while (i >= 0) {
if (p < 8){
d = ((a[i] & ((1 << p) - 1)) << (8 - p));
var _temp3 = d;
i = (i - 1);
p = (p + (DB - 8));
d = (_temp3 | (a[i] >> p));
} else {
p = (p - 8);
d = ((a[i] >> p) & 0xFF);
if (p <= 0){
p = (p + DB);
i--;
};
};
if ((d & 128) != 0){
d = (d | -256);
};
if ((((k == 0)) && (!(((s & 128) == (d & 128)))))){
k++;
};
if ((((k > 0)) || (!((d == s))))){
var _temp4 = k;
k = (k + 1);
_local6 = _temp4;
r[_local6] = d;
};
};
};
return (r);
}
bi_internal function squareTo(r:BigInteger):void{
var x:BigInteger;
var i:int;
var c:int;
x = abs();
i = (r.t = (2 * x.t));
while (--i >= 0) {
r.a[i] = 0;
};
i = 0;
while (i < (x.t - 1)) {
c = x.am(i, x.a[i], r, (2 * i), 0, 1);
if ((r.a[(i + x.t)] = (r.a[(i + x.t)] + x.am((i + 1), (2 * x.a[i]), r, ((2 * i) + 1), c, ((x.t - i) - 1)))) >= DV){
r.a[(i + x.t)] = (r.a[(i + x.t)] - DV);
r.a[((i + x.t) + 1)] = 1;
};
i++;
};
if (r.t > 0){
r.a[(r.t - 1)] = (r.a[(r.t - 1)] + x.am(i, x.a[i], r, (2 * i), 0, 1));
};
r.s = 0;
r.clamp();
}
private function op_and(x:int, y:int):int{
return ((x & y));
}
protected function fromRadix(s:String, b:int=10):void{
var cs:int;
var d:Number;
var mi:Boolean;
var j:int;
var w:int;
var i:int;
var x:int;
fromInt(0);
cs = chunkSize(b);
d = Math.pow(b, cs);
mi = false;
j = 0;
w = 0;
i = 0;
while (i < s.length) {
x = intAt(s, i);
if (x < 0){
if ((((s.charAt(i) == "-")) && ((sigNum() == 0)))){
mi = true;
};
} else {
w = ((b * w) + x);
++j;
if (j >= cs){
dMultiply(d);
dAddOffset(w, 0);
j = 0;
w = 0;
};
};
i++;
};
if (j > 0){
dMultiply(Math.pow(b, j));
dAddOffset(w, 0);
};
if (mi){
BigInteger.ZERO.subTo(this, this);
};
}
bi_internal function dlShiftTo(n:int, r:BigInteger):void{
var i:int;
i = (t - 1);
while (i >= 0) {
r.a[(i + n)] = a[i];
i--;
};
i = (n - 1);
while (i >= 0) {
r.a[i] = 0;
i--;
};
r.t = (t + n);
r.s = s;
}
private function op_xor(x:int, y:int):int{
return ((x ^ y));
}
public static function nbv(value:int):BigInteger{
var bn:BigInteger;
bn = new (BigInteger);
bn.fromInt(value);
return (bn);
}
}
}//package com.hurlant.math
Section 49
//ClassicReduction (com.hurlant.math.ClassicReduction)
package com.hurlant.math {
import com.hurlant.math.*;
class ClassicReduction implements IReduction {
private var m:BigInteger;
function ClassicReduction(m:BigInteger){
super();
this.m = m;
}
public function revert(x:BigInteger):BigInteger{
return (x);
}
public function reduce(x:BigInteger):void{
x.divRemTo(m, null, x);
}
public function convert(x:BigInteger):BigInteger{
if ((((x.s < 0)) || ((x.compareTo(m) >= 0)))){
return (x.mod(m));
};
return (x);
}
public function sqrTo(x:BigInteger, r:BigInteger):void{
x.squareTo(r);
reduce(r);
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void{
x.multiplyTo(y, r);
reduce(r);
}
}
}//package com.hurlant.math
Section 50
//IReduction (com.hurlant.math.IReduction)
package com.hurlant.math {
import com.hurlant.math.*;
interface IReduction {
function convert(:BigInteger):BigInteger;
function revert(:BigInteger):BigInteger;
function reduce(C:\ws\Crypto;com\hurlant\math;IReduction.as:BigInteger):void;
function sqrTo(_arg1:BigInteger, _arg2:BigInteger):void;
function mulTo(_arg1:BigInteger, _arg2:BigInteger, _arg3:BigInteger):void;
}
}//package com.hurlant.math
Section 51
//MontgomeryReduction (com.hurlant.math.MontgomeryReduction)
package com.hurlant.math {
import com.hurlant.math.*;
class MontgomeryReduction implements IReduction {
private var um:int;
private var mp:int;
private var mph:int;
private var mpl:int;
private var mt2:int;
private var m:BigInteger;
function MontgomeryReduction(m:BigInteger){
super();
this.m = m;
mp = m.invDigit();
mpl = (mp & 32767);
mph = (mp >> 15);
um = ((1 << (BigInteger.DB - 15)) - 1);
mt2 = (2 * m.t);
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void{
x.multiplyTo(y, r);
reduce(r);
}
public function revert(x:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
x.copyTo(r);
reduce(r);
return (r);
}
public function convert(x:BigInteger):BigInteger{
var r:BigInteger;
r = new BigInteger();
x.abs().dlShiftTo(m.t, r);
r.divRemTo(m, null, r);
if ((((x.s < 0)) && ((r.compareTo(BigInteger.ZERO) > 0)))){
m.subTo(r, r);
};
return (r);
}
public function reduce(x:BigInteger):void{
var i:int;
var j:int;
var u0:int;
while (x.t <= mt2) {
var _local5 = x.t++;
x.a[_local5] = 0;
};
i = 0;
while (i < m.t) {
j = (x.a[i] & 32767);
u0 = (((j * mpl) + ((((j * mph) + ((x.a[i] >> 15) * mpl)) & um) << 15)) & BigInteger.DM);
j = (i + m.t);
x.a[j] = (x.a[j] + m.am(0, u0, x, i, 0, m.t));
while (x.a[j] >= BigInteger.DV) {
x.a[j] = (x.a[j] - BigInteger.DV);
_local5 = x.a;
++j;
var _local6 = j;
var _local7 = (_local5[_local6] + 1);
_local5[_local6] = _local7;
};
i++;
};
x.clamp();
x.drShiftTo(m.t, x);
if (x.compareTo(m) >= 0){
x.subTo(m, x);
};
}
public function sqrTo(x:BigInteger, r:BigInteger):void{
x.squareTo(r);
reduce(r);
}
}
}//package com.hurlant.math
Section 52
//NullReduction (com.hurlant.math.NullReduction)
package com.hurlant.math {
public class NullReduction implements IReduction {
public function NullReduction(){
super();
}
public function reduce(x:BigInteger):void{
}
public function revert(x:BigInteger):BigInteger{
return (x);
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void{
x.multiplyTo(y, r);
}
public function convert(x:BigInteger):BigInteger{
return (x);
}
public function sqrTo(x:BigInteger, r:BigInteger):void{
x.squareTo(r);
}
}
}//package com.hurlant.math
Section 53
//Base64 (com.hurlant.util.Base64)
package com.hurlant.util {
import flash.utils.*;
public class Base64 {
public static const version:String = "1.0.0";
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
public function Base64(){
super();
throw (new Error("Base64 class is static container only"));
}
public static function encode(data:String):String{
var bytes:ByteArray;
bytes = new ByteArray();
bytes.writeUTFBytes(data);
return (encodeByteArray(bytes));
}
public static function encodeByteArray(data:ByteArray):String{
var output:String;
var dataBuffer:Array;
var outputBuffer:Array;
var i:uint;
var j:uint;
var k:uint;
output = "";
outputBuffer = new Array(4);
data.position = 0;
while (data.bytesAvailable > 0) {
dataBuffer = new Array();
i = 0;
while ((((i < 3)) && ((data.bytesAvailable > 0)))) {
dataBuffer[i] = data.readUnsignedByte();
i++;
};
outputBuffer[0] = ((dataBuffer[0] & 252) >> 2);
outputBuffer[1] = (((dataBuffer[0] & 3) << 4) | (dataBuffer[1] >> 4));
outputBuffer[2] = (((dataBuffer[1] & 15) << 2) | (dataBuffer[2] >> 6));
outputBuffer[3] = (dataBuffer[2] & 63);
j = dataBuffer.length;
while (j < 3) {
outputBuffer[(j + 1)] = 64;
j++;
};
k = 0;
while (k < outputBuffer.length) {
output = (output + BASE64_CHARS.charAt(outputBuffer[k]));
k++;
};
};
return (output);
}
public static function decode(data:String):String{
var bytes:ByteArray;
bytes = decodeToByteArray(data);
return (bytes.readUTFBytes(bytes.length));
}
public static function decodeToByteArray(data:String):ByteArray{
var output:ByteArray;
var dataBuffer:Array;
var outputBuffer:Array;
var i:uint;
var j:uint;
var k:uint;
output = new ByteArray();
dataBuffer = new Array(4);
outputBuffer = new Array(3);
i = 0;
while (i < data.length) {
j = 0;
while ((((j < 4)) && (((i + j) < data.length)))) {
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt((i + j)));
j++;
};
outputBuffer[0] = ((dataBuffer[0] << 2) + ((dataBuffer[1] & 48) >> 4));
outputBuffer[1] = (((dataBuffer[1] & 15) << 4) + ((dataBuffer[2] & 60) >> 2));
outputBuffer[2] = (((dataBuffer[2] & 3) << 6) + dataBuffer[3]);
k = 0;
while (k < outputBuffer.length) {
if (dataBuffer[(k + 1)] == 64){
break;
};
output.writeByte(outputBuffer[k]);
k++;
};
i = (i + 4);
};
output.position = 0;
return (output);
}
}
}//package com.hurlant.util
Section 54
//Hex (com.hurlant.util.Hex)
package com.hurlant.util {
import flash.utils.*;
public class Hex {
public function Hex(){
super();
}
public static function fromString(str:String, colons:Boolean=false):String{
var a:ByteArray;
a = new ByteArray();
a.writeUTFBytes(str);
return (fromArray(a, colons));
}
public static function toString(hex:String):String{
var a:ByteArray;
a = toArray(hex);
return (a.readUTFBytes(a.length));
}
public static function toArray(hex:String):ByteArray{
var a:ByteArray;
var i:uint;
hex = hex.replace(/\s|:/gm, "");
a = new ByteArray();
if ((hex.length & (1 == 1))){
hex = ("0" + hex);
};
i = 0;
while (i < hex.length) {
a[(i / 2)] = parseInt(hex.substr(i, 2), 16);
i = (i + 2);
};
return (a);
}
public static function fromArray(array:ByteArray, colons:Boolean=false):String{
var s:String;
var i:uint;
s = "";
i = 0;
while (i < array.length) {
s = (s + ("0" + array[i].toString(16)).substr(-2, 2));
if (colons){
if (i < (array.length - 1)){
s = (s + ":");
};
};
i++;
};
return (s);
}
}
}//package com.hurlant.util
Section 55
//Memory (com.hurlant.util.Memory)
package com.hurlant.util {
import flash.system.*;
import flash.net.*;
public class Memory {
public function Memory(){
super();
}
public static function gc():void{
new LocalConnection().connect("foo");
new LocalConnection().connect("foo");
//unresolved jump
var _slot1 = e;
}
public static function get used():uint{
return (System.totalMemory);
}
}
}//package com.hurlant.util
Section 56
//Card (components.Card)
package components {
public class Card extends CardGfx {
public var value:String;
public function Card(){
super();
gotoAndStop(1);
}
public function setValue(v:String):void{
value = v;
gotoAndStop(v);
}
}
}//package components
Section 57
//EndGamePage (components.EndGamePage)
package components {
import flash.events.*;
import com.greenish.onlinegames.events.*;
import flash.display.*;
import flash.text.*;
public class EndGamePage extends MovieClip {
private var score:Number;
private var candystand;
public function EndGamePage(score:Number, time:Number, type:String, candystand){
super();
var go:EndGameGfx = new EndGameGfx();
var txt:TextField = (go["endTxt"] as TextField);
txt.text = score.toString();
this.score = score;
this.candystand = candystand;
if (type == GameEvent.THEEND){
go.goTxt.gotoAndStop("GAME_OVER");
} else {
if (type == GameEvent.TIMEOUT){
go.goTxt.gotoAndStop("OUT_OF_TIME");
};
};
addChild(go);
go.submit.addEventListener(MouseEvent.CLICK, onSubmitClick);
go.retry.addEventListener(MouseEvent.CLICK, onRetryClick);
}
private function onSubmitClick(e:MouseEvent):void{
candystand.game.score = score;
candystand.game.submitScore();
}
private function onRetryClick(e:MouseEvent):void{
parent.removeChild(this);
dispatchEvent(new GameEvent(GameEvent.RETRY));
}
}
}//package components
Section 58
//Slider (components.Slider)
package components {
import flash.events.*;
import events.*;
import caurina.transitions.*;
public class Slider extends SliderGfx {
private var sX:Number;
private var _position:Number;
public var places:Array;
private var dropShadowEffect:Array;
private var cards:Array;
private var where:Array;
public function Slider(){
places = new Array(0, 26, 90, 154, 218, 282);
where = new Array(0, 412, 348, 284, 220, 156);
super();
stop();
position = 3;
cards = new Array();
}
public function getCard(place:Number):Card{
return ((cards[place] as Card));
}
public function set position(p:Number):void{
_position = p;
}
public function checkLength():Number{
var card:Card;
var arr:Array = new Array();
var i:int = (cards.length - 1);
while (i >= 1) {
card = (cards[i] as Card);
if (card == null){
arr.push(i);
cards.splice(i, 1);
};
i--;
};
gotoAndStop((7 - cards.length));
i = (cards.length - 1);
while (i >= 1) {
card = (cards[i] as Card);
Tweener.addTween(card, {x:places[i], time:0.05});
i--;
};
var o:Object = {};
o.times = 0;
Tweener.addTween(o, {times:1, time:0.05, onComplete:onUp});
return ((cards.length - 1));
}
public function onUp(e:MouseEvent=null):void{
var now:Number = Math.round(((x - 144) / 70));
if (now < (5 - (cards.length - 1))){
now = (5 - (cards.length - 1));
};
x = where[(5 - now)];
position = (5 - now);
if (now == 0){
leftArrow.visible = false;
} else {
leftArrow.visible = true;
};
if (now == 4){
rightArrow.visible = false;
} else {
rightArrow.visible = true;
};
if ((cards.length - 1) > 0){
dispatchEvent(new SliderEvent(now, "MOVE"));
};
}
public function removeListeners():void{
removeEventListener(MouseEvent.MOUSE_DOWN, onPress);
}
private function moving(e:Event):void{
var nx:Number = (parent.mouseX - sX);
if (nx > 412){
x = 412;
} else {
if (nx < (156 + ((5 - (cards.length - 1)) * 67))){
x = (156 + ((5 - (cards.length - 1)) * 67));
} else {
x = nx;
};
};
}
public function highlightRow():void{
var card:Card = (cards[position] as Card);
var i = 1;
while (i < cards.length) {
card = (cards[i] as Card);
if (card){
card.greenGlow.visible = true;
card.cardBack.filters = [];
};
i++;
};
}
public function setTheCard(card:Card, place:Number):void{
dropShadowEffect = card.cardBack.filters;
cards[place] = card;
card.x = places[place];
card.y = 5;
addChild(card);
}
public function removeActiveCard():void{
var card:Card = (cards[position] as Card);
removeChild(card);
var i:int = (position - 1);
while (i >= 1) {
card = (cards[i] as Card);
Tweener.addTween(card, {x:places[(i + 1)], time:0.2});
cards[(i + 1)] = card;
i--;
};
cards[1] = null;
}
private function onPress(e:MouseEvent):void{
sX = mouseX;
stage.addEventListener(MouseEvent.MOUSE_UP, onUpMouse);
addEventListener(Event.ENTER_FRAME, moving);
dispatchEvent(new SliderEvent(0, "MOVING"));
}
public function get position():Number{
var now:Number = Math.round(((x - 144) / 70));
if (now < (5 - (cards.length - 1))){
now = (5 - (cards.length - 1));
};
_position = (5 - now);
return (_position);
}
public function createListeners():void{
addEventListener(MouseEvent.MOUSE_DOWN, onPress);
}
public function onUpMouse(e:MouseEvent=null):void{
var now:Number = Math.round(((x - 144) / 70));
if (now < (5 - (cards.length - 1))){
now = (5 - (cards.length - 1));
};
x = where[(5 - now)];
position = (5 - now);
if (now == 0){
leftArrow.visible = false;
} else {
leftArrow.visible = true;
};
if (now == 4){
rightArrow.visible = false;
} else {
rightArrow.visible = true;
};
stage.removeEventListener(MouseEvent.MOUSE_UP, onUpMouse);
removeEventListener(Event.ENTER_FRAME, moving);
if ((cards.length - 1) > 0){
dispatchEvent(new SliderEvent(now, "MOVE"));
};
}
public function unHighlightRow():void{
var card:Card = (cards[position] as Card);
var i = 1;
while (i < cards.length) {
card = (cards[i] as Card);
if (card){
if (card.greenGlow){
card.greenGlow.visible = false;
};
if (dropShadowEffect != null){
card.cardBack.filters = dropShadowEffect;
};
};
i++;
};
}
}
}//package components
Section 59
//SliderEvent (events.SliderEvent)
package events {
import flash.events.*;
public class SliderEvent extends Event {
public var eventType:String;
public var place:Number;
public static var MOVED:String = "onMoved";
public static var MOVING:String = "onMoving";
public function SliderEvent(place:Number, type:String){
if (type == "MOVE"){
eventType = MOVED;
} else {
eventType = MOVING;
};
super(eventType);
this.place = place;
}
}
}//package events
Section 60
//goTxt_44 (game_fla.goTxt_44)
package game_fla {
import flash.display.*;
public dynamic class goTxt_44 extends MovieClip {
public function goTxt_44(){
addFrameScript(0, frame1, 1, frame2);
}
function frame1(){
stop();
}
function frame2(){
stop();
}
}
}//package game_fla
Section 61
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 62
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 63
//SoundAsset (mx.core.SoundAsset)
package mx.core {
import flash.media.*;
public class SoundAsset extends Sound implements IFlexAsset {
mx_internal static const VERSION:String = "3.5.0.12683";
public function SoundAsset(){
super();
}
}
}//package mx.core
Section 64
//CardGfx (CardGfx)
package {
import flash.display.*;
public dynamic class CardGfx extends MovieClip {
public var cardBack:MovieClip;
public var greenGlow:MovieClip;
public function CardGfx(){
addFrameScript(0, frame1, 1, frame2, 2, frame3, 3, frame4, 4, frame5, 5, frame6, 6, frame7, 7, frame8, 8, frame9, 9, frame10, 10, frame11, 11, frame12, 12, frame13, 13, frame14, 14, frame15, 15, frame16, 16, frame17, 17, frame18, 18, frame19, 19, frame20, 20, frame21, 21, frame22, 22, frame23, 23, frame24, 24, frame25, 25, frame26, 26, frame27, 27, frame28, 28, frame29, 29, frame30, 30, frame31, 31, frame32, 32, frame33, 33, frame34, 34, frame35, 35, frame36, 36, frame37, 37, frame38, 38, frame39, 39, frame40, 40, frame41, 41, frame42, 42, frame43, 43, frame44, 44, frame45, 45, frame46, 46, frame47, 47, frame48, 48, frame49, 49, frame50, 50, frame51, 51, frame52, 52, frame53, 53, frame54);
}
function frame30(){
stop();
}
function frame31(){
stop();
}
function frame32(){
stop();
}
function frame33(){
stop();
}
function frame34(){
stop();
}
function frame35(){
stop();
}
function frame36(){
stop();
}
function frame37(){
stop();
}
function frame38(){
stop();
}
function frame39(){
stop();
}
function frame40(){
stop();
}
function frame41(){
stop();
}
function frame42(){
stop();
}
function frame43(){
stop();
}
function frame44(){
stop();
}
function frame46(){
stop();
}
function frame48(){
stop();
}
function frame49(){
stop();
}
function frame45(){
stop();
}
function frame47(){
stop();
}
function frame50(){
stop();
}
function frame51(){
stop();
}
function frame52(){
stop();
}
function frame53(){
stop();
}
function frame10(){
stop();
}
function frame11(){
stop();
}
function frame12(){
stop();
}
function frame13(){
stop();
}
function frame14(){
stop();
}
function frame15(){
stop();
}
function frame16(){
stop();
}
function frame17(){
stop();
}
function frame18(){
stop();
}
function frame19(){
stop();
}
function frame54(){
stop();
}
function frame1(){
stop();
}
function frame2(){
stop();
}
function frame3(){
stop();
}
function frame4(){
stop();
}
function frame5(){
stop();
}
function frame6(){
stop();
}
function frame7(){
stop();
}
function frame20(){
stop();
}
function frame9(){
stop();
}
function frame22(){
stop();
}
function frame23(){
stop();
}
function frame24(){
stop();
}
function frame25(){
stop();
}
function frame26(){
stop();
}
function frame8(){
stop();
}
function frame21(){
stop();
}
function frame29(){
stop();
}
function frame27(){
stop();
}
function frame28(){
stop();
}
}
}//package
Section 65
//EndGameGfx (EndGameGfx)
package {
import flash.display.*;
import flash.text.*;
public dynamic class EndGameGfx extends MovieClip {
public var goTxt:MovieClip;
public var endTxt:TextField;
public var retry:SimpleButton;
public var submit:SimpleButton;
}
}//package
Section 66
//ErrorGfx (ErrorGfx)
package {
import flash.display.*;
public dynamic class ErrorGfx extends MovieClip {
}
}//package
Section 67
//Game (Game)
package {
import flash.events.*;
import com.greenish.onlinegames.events.*;
import events.*;
import components.*;
import caurina.transitions.*;
import flash.display.*;
import flash.net.*;
import flash.ui.*;
public class Game extends MovieClip {
private var rowGlow:Array;
private var score:Number;// = 0
private var gameGfx:GameGfx;
private var koloda:Array;
private var activeScore:Number;// = 0
private var rowSelected:int;// = 3
private var paused:PauseGfx;
private var kolodaShow:KolodaShow;
private var time:Number;// = 300
private var lenCards:Number;// = 0
private var slider1:Slider;
private var slider2:Slider;
private var slider3:Slider;
private var slider4:Slider;
private var slider5:Slider;
private var timerObj:Object;
private var timeToAction:Number;// = 0.2
public function Game(gameGfx:GameGfx){
super();
this.gameGfx = gameGfx;
addChild(gameGfx);
gameGfx.rules.visible = false;
gameGfx.soundBut.addEventListener(MouseEvent.CLICK, onClickSoundOff);
gameGfx.soundOnBut.addEventListener(MouseEvent.CLICK, onClickSoundOn);
gameGfx.pauseBut.addEventListener(MouseEvent.CLICK, onClickPause);
gameGfx.rulesBut.addEventListener(MouseEvent.CLICK, onClickRules);
gameGfx.rules.closeBut.addEventListener(MouseEvent.CLICK, onClickRulesClose);
if (!MusicLibrary.isMute){
gameGfx.soundOnBut.visible = false;
gameGfx.soundBut.visible = true;
} else {
gameGfx.soundOnBut.visible = true;
gameGfx.soundBut.visible = false;
};
updateScore(0);
setCombi("NOTHING");
createGame();
}
private function startTimer():void{
timerObj = new Object();
timerObj.timer = time;
Tweener.addTween(timerObj, {timer:0, time:time, transition:"easenone", onComplete:timeIsOut, onUpdate:OnTimerUpdate});
pauseTimer();
}
private function onKeyPressed(e:KeyboardEvent):void{
var slider:Slider = this[("slider" + rowSelected.toString())];
if (!gameGfx.submitButton.visible){
return;
};
switch (e.keyCode){
case Keyboard.LEFT:
if (slider.position < 5){
slider.x = (slider.x - 70);
slider.onUp();
};
break;
case Keyboard.RIGHT:
if (slider.position > 1){
slider.x = (slider.x + 70);
slider.onUp();
};
break;
case Keyboard.UP:
selectRow(Math.max((rowSelected - 1), 1));
break;
case Keyboard.DOWN:
selectRow(Math.min((rowSelected + 1), 5));
break;
case Keyboard.ENTER:
onSubmit();
break;
case Keyboard.SPACE:
onSubmit();
break;
case Keyboard.NUMPAD_ENTER:
onSubmit();
break;
};
}
private function onClickRulesClose(e:MouseEvent):void{
MusicLibrary.resume();
Tweener.resumeAllTweens();
gameGfx.rules.visible = false;
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
}
private function onClickPause(e:MouseEvent):void{
MusicLibrary.pause();
Tweener.pauseAllTweens();
paused = new PauseGfx();
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
paused.continueBut.addEventListener(MouseEvent.CLICK, onUnPaused);
paused.blocker.addEventListener(MouseEvent.CLICK, onUnPaused);
stage.addChild(paused);
}
private function createGame():void{
var mast:String;
var j:int;
var yy:Number = 43;
var i = 1;
while (i <= 5) {
this[("slider" + i.toString())] = new Slider();
this[("slider" + i.toString())].x = 283;
this[("slider" + i.toString())].y = yy;
this[("slider" + i.toString())].addEventListener(SliderEvent.MOVED, onMovedSlider);
this[("slider" + i.toString())].addEventListener(SliderEvent.MOVING, onMovingSlider);
yy = (yy + 100);
gameGfx.sliders.addChild(this[("slider" + i.toString())]);
i++;
};
gameGfx.kolodaShow.stop();
gameGfx.kolodaShow.visible = false;
var masti:Array = new Array("Piki", "Cherv", "Tref", "Bubi");
var cards:Array = new Array("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A");
var cardsArrTemp:Array = new Array();
i = 0;
while (i < masti.length) {
mast = masti[i];
j = 0;
while (j < cards.length) {
cardsArrTemp.push(((cards[j] + "-") + mast));
j++;
};
i++;
};
cardsArrTemp.push("jocker-jocker");
cardsArrTemp.push("jocker-jocker");
cardsArrTemp.push("jocker-jocker");
lenCards = cardsArrTemp.length;
cardsArrTemp = shuffleCards(cardsArrTemp);
cardsArrTemp = shuffleCards(cardsArrTemp);
koloda = shuffleCards(cardsArrTemp);
getNew25Cards();
}
private function enableSubmit():void{
var slider:Slider;
trace("enable");
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
slider.createListeners();
i++;
};
gameGfx.subdis.visible = false;
gameGfx.submitButton.visible = true;
resumeTimer();
}
private function onSliderOver(e:MouseEvent):void{
var slider:Slider;
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
if ((((slider == e.target)) || ((slider == e.target.parent)))){
selectRow(i);
return;
};
i++;
};
}
private function resumeTimer():void{
}
private function onClickRules(e:MouseEvent):void{
MusicLibrary.pause();
Tweener.pauseAllTweens();
gameGfx.rules.visible = true;
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
}
private function getNew5Cards():void{
var cardholder:Card;
var v:String;
var sl:Slider;
var card:Card;
var wx:Number;
var wy:Number;
var cards:Array = koloda.splice(0, 5);
var nx:Number = 1;
var ny:Number = 1;
var delay:Number = 0;
MusicLibrary.playSound(MusicLibrary.FlyClass, 0.5);
for each (v in cards) {
sl = (this[("slider" + ny.toString())] as Slider);
card = new Card();
card.x = (gameGfx.kolodaShow.x + 2);
card.y = (gameGfx.kolodaShow.y + 2);
card.alpha = 1;
card.mouseChildren = false;
card.mouseEnabled = false;
card.greenGlow.visible = false;
gameGfx.addChild(card);
wx = (sl.x + sl.places[nx]);
wy = (sl.y + 5);
card.setValue(v);
Tweener.addTween(card, {delay:delay, x:wx, y:wy, alpha:1, time:timeToAction, onComplete:setCardToSlider, onCompleteParams:[card, sl, v, nx]});
delay = (delay + timeToAction);
if (ny < 5){
ny = (ny + 1);
} else {
ny = 1;
nx--;
};
cardholder = card;
};
if (cards.length > 0){
gameGfx.swapChildren(this.kolodaShow, cardholder);
};
var o:Object = {};
o.times = 0;
Tweener.addTween(o, {times:1, time:(cards.length * timeToAction), onComplete:setSubmitActive});
}
private function disableSubmit():void{
var slider:Slider;
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
slider.removeListeners();
i++;
};
gameGfx.subdis.visible = true;
gameGfx.submitButton.visible = false;
pauseTimer();
}
private function onClickSoundOn(e:MouseEvent):void{
MusicLibrary.changeMute();
gameGfx.soundOnBut.visible = false;
gameGfx.soundBut.visible = true;
}
private function onUnPaused(e:MouseEvent):void{
MusicLibrary.resume();
Tweener.resumeAllTweens();
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
stage.focus = stage;
paused.continueBut.removeEventListener(MouseEvent.CLICK, onUnPaused);
paused.blocker.removeEventListener(MouseEvent.CLICK, onUnPaused);
stage.removeChild(paused);
}
private function onClickLogo(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.onlinegamestars.com/"), "_blank");
}
private function getNew25Cards():void{
var v:String;
var o:Object;
var sl:Slider;
var card:Card;
var wx:Number;
var wy:Number;
var cards:Array = koloda.splice(0, 25);
var nx:Number = 5;
var ny:Number = 1;
var delay:Number = 0;
MusicLibrary.playSound(MusicLibrary.FlyClass, 0.5);
for each (v in cards) {
sl = (this[("slider" + ny.toString())] as Slider);
card = new Card();
card.x = (gameGfx.kolodaShow.x + 2);
card.y = (gameGfx.kolodaShow.y + 2);
card.alpha = 1;
card.mouseChildren = false;
card.mouseEnabled = false;
card.greenGlow.visible = false;
gameGfx.addChild(card);
wx = (sl.x + sl.places[nx]);
wy = (sl.y + 5);
card.setValue(v);
Tweener.addTween(card, {delay:delay, x:wx, y:wy, alpha:1, time:timeToAction, onComplete:setCardToSlider, onCompleteParams:[card, sl, v, nx]});
delay = (delay + timeToAction);
if (ny < 5){
ny = (ny + 1);
} else {
ny = 1;
nx--;
};
};
this.kolodaShow = new KolodaShow();
this.kolodaShow.x = gameGfx.kolodaShow.x;
this.kolodaShow.y = gameGfx.kolodaShow.y;
gameGfx.addChild(this.kolodaShow);
o = {};
o.times = 0;
Tweener.addTween(o, {times:1, time:(cards.length * timeToAction), onComplete:startGame});
}
private function onMovedSlider(e:SliderEvent=null):void{
var slider:Slider;
var card:Card;
enableSubmit();
var arr:Array = new Array();
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
card = slider.getCard(slider.position);
arr.push(card.value);
i++;
};
checkCombi(arr);
}
private function selectRow(n:int):void{
var i = 1;
while (i <= 5) {
this[("slider" + i.toString())].unHighlightRow();
i++;
};
rowSelected = n;
this[("slider" + rowSelected.toString())].highlightRow();
}
private function setSubmitActive():void{
var slider:Slider;
var counter:Number;
var o:Object;
var arr:Array;
var j:int;
var sliderCheck:Slider;
var card:Card;
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
counter = slider.checkLength();
i++;
};
if (counter > 0){
o = {};
o.times = 0;
Tweener.addTween(o, {times:1, time:0.07});
selectRow(rowSelected);
trace("YES");
enableSubmit();
arr = new Array();
j = 1;
while (j <= 5) {
sliderCheck = (this[("slider" + j.toString())] as Slider);
card = sliderCheck.getCard(sliderCheck.position);
arr.push(card.value);
j++;
};
checkCombi(arr);
} else {
i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
slider.visible = false;
i++;
};
MusicLibrary.playSound(MusicLibrary.EndClass, 0.5);
dispatchEvent(new GameEvent(GameEvent.THEEND, score, Math.floor(timerObj.timer)));
Tweener.removeTweens(timerObj);
};
}
private function setCombi(txt:String):void{
var num:Number;
var activeScoreT:String;
gameGfx.combiTxt.text = txt;
switch (txt){
case "NOTHING":
num = 0;
break;
case "ONE PAIR":
num = 300;
break;
case "TWO PAIRS":
num = 500;
break;
case "THREE OF A KIND":
num = 700;
break;
case "STRAIGHT":
num = 900;
break;
case "FOUR OF A KIND":
num = 1500;
break;
case "FULL HOUSE":
num = 1200;
break;
case "FLUSH":
num = 1000;
break;
case "STRAIGHT FLUSH":
num = 1800;
break;
case "ROYAL FLUSH":
num = 2500;
break;
};
activeScore = num;
if (activeScore < 10){
activeScoreT = ("0000" + activeScore.toString());
gameGfx.futureTxt.digitComma.visible = false;
gameGfx.futureTxt.digit0.visible = true;
gameGfx.futureTxt.digit1.visible = false;
gameGfx.futureTxt.digit2.visible = false;
gameGfx.futureTxt.digit3.visible = false;
gameGfx.futureTxt.digit4.visible = false;
} else {
if (activeScore < 100){
activeScoreT = ("000" + activeScore.toString());
gameGfx.futureTxt.digitComma.visible = false;
gameGfx.futureTxt.digit0.visible = true;
gameGfx.futureTxt.digit1.visible = true;
gameGfx.futureTxt.digit2.visible = false;
gameGfx.futureTxt.digit3.visible = false;
gameGfx.futureTxt.digit4.visible = false;
} else {
if (activeScore < 1000){
activeScoreT = ("00" + activeScore.toString());
gameGfx.futureTxt.digitComma.visible = false;
gameGfx.futureTxt.digit0.visible = true;
gameGfx.futureTxt.digit1.visible = true;
gameGfx.futureTxt.digit2.visible = true;
gameGfx.futureTxt.digit3.visible = false;
gameGfx.futureTxt.digit4.visible = false;
} else {
if (activeScore < 10000){
activeScoreT = ("0" + activeScore.toString());
gameGfx.futureTxt.digitComma.visible = true;
gameGfx.futureTxt.digit0.visible = true;
gameGfx.futureTxt.digit1.visible = true;
gameGfx.futureTxt.digit2.visible = true;
gameGfx.futureTxt.digit3.visible = true;
gameGfx.futureTxt.digit4.visible = false;
} else {
activeScoreT = activeScore.toString();
gameGfx.futureTxt.digitComma.visible = true;
gameGfx.futureTxt.digitComma.visible = true;
gameGfx.futureTxt.digit0.visible = true;
gameGfx.futureTxt.digit1.visible = true;
gameGfx.futureTxt.digit2.visible = true;
gameGfx.futureTxt.digit3.visible = true;
gameGfx.futureTxt.digit4.visible = true;
};
};
};
};
gameGfx.futureTxt.digit0.text = activeScoreT.charAt(4);
gameGfx.futureTxt.digit1.text = activeScoreT.charAt(3);
gameGfx.futureTxt.digit2.text = activeScoreT.charAt(2);
gameGfx.futureTxt.digit3.text = activeScoreT.charAt(1);
gameGfx.futureTxt.digit4.text = activeScoreT.charAt(0);
}
private function updateScore(s:Number):void{
var scoreT:String;
score = (score + s);
if (score < 10){
scoreT = ("0000" + score.toString());
gameGfx.scoreTxt.digitComma.visible = false;
gameGfx.scoreTxt.digit0.visible = true;
gameGfx.scoreTxt.digit1.visible = false;
gameGfx.scoreTxt.digit2.visible = false;
gameGfx.scoreTxt.digit3.visible = false;
gameGfx.scoreTxt.digit4.visible = false;
} else {
if (score < 100){
scoreT = ("000" + score.toString());
gameGfx.scoreTxt.digitComma.visible = false;
gameGfx.scoreTxt.digit0.visible = true;
gameGfx.scoreTxt.digit1.visible = true;
gameGfx.scoreTxt.digit2.visible = false;
gameGfx.scoreTxt.digit3.visible = false;
gameGfx.scoreTxt.digit4.visible = false;
} else {
if (score < 1000){
scoreT = ("00" + score.toString());
gameGfx.scoreTxt.digitComma.visible = false;
gameGfx.scoreTxt.digit0.visible = true;
gameGfx.scoreTxt.digit1.visible = true;
gameGfx.scoreTxt.digit2.visible = true;
gameGfx.scoreTxt.digit3.visible = false;
gameGfx.scoreTxt.digit4.visible = false;
} else {
if (score < 10000){
scoreT = ("0" + score.toString());
gameGfx.scoreTxt.digitComma.visible = true;
gameGfx.scoreTxt.digit0.visible = true;
gameGfx.scoreTxt.digit1.visible = true;
gameGfx.scoreTxt.digit2.visible = true;
gameGfx.scoreTxt.digit3.visible = true;
gameGfx.scoreTxt.digit4.visible = false;
} else {
scoreT = score.toString();
gameGfx.scoreTxt.digitComma.visible = true;
gameGfx.scoreTxt.digit0.visible = true;
gameGfx.scoreTxt.digit1.visible = true;
gameGfx.scoreTxt.digit2.visible = true;
gameGfx.scoreTxt.digit3.visible = true;
gameGfx.scoreTxt.digit4.visible = true;
};
};
};
};
gameGfx.scoreTxt.digit0.text = scoreT.charAt(4);
gameGfx.scoreTxt.digit1.text = scoreT.charAt(3);
gameGfx.scoreTxt.digit2.text = scoreT.charAt(2);
gameGfx.scoreTxt.digit3.text = scoreT.charAt(1);
gameGfx.scoreTxt.digit4.text = scoreT.charAt(0);
}
private function onMovingSlider(e:SliderEvent=null):void{
disableSubmit();
}
private function onSubmit(e:MouseEvent=null):void{
var slider:Slider;
MusicLibrary.playSound(MusicLibrary.SubmitClass, 0.5);
disableSubmit();
updateScore(activeScore);
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
slider.removeActiveCard();
i++;
};
getNew5Cards();
}
private function onClickMore(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.onlinegamestars.com/English/sitegames.html"), "_blank");
}
private function checkCombi(cards:Array):void{
var cm:Number;
var card:String;
var ex:Array;
var v:Number;
var sovpalo:Number;
var jockersTemp:Number;
var wasBreak:Boolean;
var nowValue:Number;
var q:int;
var isKare:Boolean;
var isSet:Boolean;
var isPair:Number;
var was:String;
var s:String;
var c:Number;
var was1:String;
var qq:int;
trace("checking combi");
var howManyMast:Object = {Piki:0, Cherv:0, Tref:0, Bubi:0, jocker:0};
var howManyCards:Object = {2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, J:0, Q:0, K:0, A:0, jocker:0};
var valueArr:Array = new Array();
var mastArr:Array = new Array();
var countJockers:Number = 0;
var isWasTuz:Boolean;
var i:int;
while (i < cards.length) {
card = (cards[i] as String);
ex = String(card).split("-");
mastArr.push(ex[1]);
if (ex[1] != "jocker"){
howManyMast[ex[1]] = (howManyMast[ex[1]] + 1);
} else {
countJockers = (countJockers + 1);
};
if (Number(ex[0])){
v = Number(ex[0]);
} else {
if (ex[0] == "J"){
v = 11;
} else {
if (ex[0] == "Q"){
v = 12;
} else {
if (ex[0] == "K"){
v = 13;
} else {
if (ex[0] == "A"){
isWasTuz = true;
v = 14;
} else {
if (ex[0] == "jocker"){
v = 100;
};
};
};
};
};
};
valueArr.push(v);
howManyCards[ex[0]] = (howManyCards[ex[0]] + 1);
i++;
};
valueArr.sort(Array.NUMERIC);
var isFlash:Boolean;
for each (cm in howManyMast) {
if ((cm + countJockers) >= 5){
isFlash = true;
break;
};
};
if (isFlash){
sovpalo = 1;
jockersTemp = countJockers;
wasBreak = false;
nowValue = valueArr[0];
i = 1;
while (i <= ((valueArr.length - 1) - countJockers)) {
if (valueArr[i] == (nowValue + 1)){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
} else {
if (jockersTemp > 0){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
jockersTemp--;
if ((nowValue + 1) != valueArr[(i - 1)]){
i--;
};
} else {
wasBreak = true;
break;
};
};
i++;
};
if (((((sovpalo + jockersTemp) >= 5)) && (!(wasBreak)))){
if ((((((((((((valueArr[0] >= 10)) && ((((valueArr[0] == 10)) || ((valueArr[4] == 100)))))) && ((((valueArr[1] == 11)) || ((valueArr[4] == 100)))))) && ((((valueArr[2] == 12)) || ((valueArr[4] == 100)))))) && ((((valueArr[3] == 13)) || ((valueArr[4] == 100)))))) && ((((valueArr[4] == 14)) || ((valueArr[4] == 100)))))){
setCombi("ROYAL FLUSH");
} else {
setCombi("STRAIGHT FLUSH");
};
} else {
if (isWasTuz){
q = 0;
while (q < valueArr.length) {
if (valueArr[q] == 14){
valueArr[q] = 1;
};
q++;
};
valueArr.sort(Array.NUMERIC);
sovpalo = 1;
jockersTemp = countJockers;
wasBreak = false;
nowValue = valueArr[0];
i = 1;
while (i <= ((valueArr.length - 1) - countJockers)) {
if (valueArr[i] == (nowValue + 1)){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
} else {
if (jockersTemp > 0){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
jockersTemp--;
if ((nowValue + 1) != valueArr[(i - 1)]){
i--;
};
} else {
wasBreak = true;
break;
};
};
i++;
};
if (((((sovpalo + jockersTemp) >= 5)) && (!(wasBreak)))){
setCombi("STRAIGHT FLUSH");
} else {
setCombi("FLUSH");
};
} else {
setCombi("FLUSH");
};
};
} else {
isKare = false;
isSet = false;
isPair = 0;
jockersTemp = countJockers;
for (s in howManyCards) {
if (s != "jocker"){
c = howManyCards[s];
if ((c + jockersTemp) >= 4){
isKare = true;
jockersTemp = (jockersTemp - (4 - c));
};
};
};
if (!isKare){
for (s in howManyCards) {
if (s != "jocker"){
c = howManyCards[s];
if ((c + jockersTemp) >= 3){
isSet = true;
was = s;
jockersTemp = (jockersTemp - (3 - c));
};
};
};
for (s in howManyCards) {
if (((((!((s == "jocker"))) && (!((s == was))))) && (!((s == was1))))){
c = howManyCards[s];
if ((c + jockersTemp) >= 2){
isPair = (isPair + 1);
was1 = s;
jockersTemp = (jockersTemp - (2 - c));
};
};
};
};
if (isKare){
setCombi("FOUR OF A KIND");
} else {
if (((isSet) && (isPair))){
setCombi("FULL HOUSE");
} else {
sovpalo = 1;
jockersTemp = countJockers;
wasBreak = false;
nowValue = valueArr[0];
i = 1;
while (i <= ((valueArr.length - 1) - countJockers)) {
if (valueArr[i] == (nowValue + 1)){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
} else {
if (jockersTemp > 0){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
jockersTemp--;
if ((nowValue + 1) != valueArr[(i - 1)]){
i--;
};
} else {
wasBreak = true;
break;
};
};
i++;
};
if (((((sovpalo + jockersTemp) >= 5)) && (!(wasBreak)))){
setCombi("STRAIGHT");
} else {
if (isWasTuz){
qq = 0;
while (qq < valueArr.length) {
if (valueArr[qq] == 14){
valueArr[qq] = 1;
};
qq++;
};
valueArr.sort(Array.NUMERIC);
sovpalo = 1;
jockersTemp = countJockers;
wasBreak = false;
nowValue = valueArr[0];
i = 1;
while (i <= ((valueArr.length - 1) - countJockers)) {
if (valueArr[i] == (nowValue + 1)){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
} else {
if (jockersTemp > 0){
nowValue = (nowValue + 1);
sovpalo = (sovpalo + 1);
jockersTemp--;
if ((nowValue + 1) != valueArr[(i - 1)]){
i--;
};
} else {
wasBreak = true;
break;
};
};
i++;
};
if (((((sovpalo + jockersTemp) >= 5)) && (!(wasBreak)))){
setCombi("STRAIGHT");
} else {
if (isSet){
setCombi("THREE OF A KIND");
} else {
if (isPair == 2){
setCombi("TWO PAIRS");
} else {
if (isPair == 1){
setCombi("ONE PAIR");
} else {
setCombi("NOTHING");
};
};
};
};
} else {
if (isSet){
setCombi("THREE OF A KIND");
} else {
if (isPair == 2){
setCombi("TWO PAIRS");
} else {
if (isPair == 1){
setCombi("ONE PAIR");
} else {
setCombi("NOTHING");
};
};
};
};
};
};
};
};
}
private function onClickSoundOff(e:MouseEvent):void{
MusicLibrary.changeMute();
gameGfx.soundOnBut.visible = true;
gameGfx.soundBut.visible = false;
}
private function shuffleCards(array:Array):Array{
var randomizedArray:Array = new Array();
while (array.length) {
randomizedArray.push(array.splice(Math.floor((Math.random() * array.length)), 1)[0]);
};
return (randomizedArray);
}
private function setCardToSlider(card:Card, slider:Slider, v:String, nx:Number):void{
var lenCardsT:String;
MusicLibrary.playSound(MusicLibrary.FlyClass, 0.5);
lenCards = (lenCards - 1);
if (lenCards < 10){
lenCardsT = ("0" + lenCards.toString());
gameGfx.kolodaTxt.digit0.visible = true;
gameGfx.kolodaTxt.digit1.visible = false;
} else {
lenCardsT = lenCards.toString();
gameGfx.kolodaTxt.digit0.visible = true;
gameGfx.kolodaTxt.digit1.visible = true;
};
gameGfx.kolodaTxt.digit0.text = lenCardsT.charAt(1);
gameGfx.kolodaTxt.digit1.text = lenCardsT.charAt(0);
slider.setTheCard(card, nx);
}
private function pauseTimer():void{
}
private function OnTimerUpdate():void{
var t:Number = Math.floor(timerObj.timer);
var min:Number = Math.floor((t / 60));
var sec:Number = Math.floor((t - (min * 60)));
var minT:String = min.toString();
var secT:String = ((sec)<10) ? ("0" + sec.toString()) : sec.toString();
gameGfx.timeTxt.digit0.text = secT.charAt(1);
gameGfx.timeTxt.digit1.text = secT.charAt(0);
gameGfx.timeTxt.digit2.text = minT;
}
private function timeIsOut():void{
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
dispatchEvent(new GameEvent(GameEvent.TIMEOUT, score, Math.floor(timerObj.timer)));
MusicLibrary.playSound(MusicLibrary.TimeoutClass, 0.5);
}
private function startGame():void{
var slider:Slider;
gameGfx.kolodaShow.gotoAndStop(2);
var i = 1;
while (i <= 5) {
slider = (this[("slider" + i.toString())] as Slider);
slider.createListeners();
selectRow(rowSelected);
slider.addEventListener(MouseEvent.MOUSE_OVER, onSliderOver);
i++;
};
gameGfx.submitButton.addEventListener(MouseEvent.CLICK, onSubmit);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
stage.focus = stage;
onMovedSlider();
startTimer();
}
}
}//package
Section 68
//GameGfx (GameGfx)
package {
import flash.display.*;
import flash.text.*;
public dynamic class GameGfx extends MovieClip {
public var kolodaShow:KolodaShow;
public var combiTxt:TextField;
public var rulesBut:SimpleButton;
public var subdis:MovieClip;
public var soundOnBut:SimpleButton;
public var timeTxt:MovieClip;
public var submitButton:SimpleButton;
public var pauseBut:SimpleButton;
public var kolodaTxt:MovieClip;
public var futureTxt:MovieClip;
public var sliders:MovieClip;
public var rules:MovieClip;
public var soundBut:SimpleButton;
public var scoreTxt:MovieClip;
}
}//package
Section 69
//KolodaShow (KolodaShow)
package {
import flash.display.*;
public dynamic class KolodaShow extends MovieClip {
}
}//package
Section 70
//LoaderGfx (LoaderGfx)
package {
import flash.display.*;
public dynamic class LoaderGfx extends MovieClip {
}
}//package
Section 71
//Main (Main)
package {
import flash.events.*;
import com.greenish.onlinegames.events.*;
import components.*;
import com.greenish.onlinegames.*;
import flash.net.*;
public class Main extends MainClass {
private var leaders:LoaderGfx;
private var candystand;
private var rules:RulesGfx;
private var isWasRules:Boolean;// = false
public function Main(candystand):void{
super();
this.candystand = candystand;
MusicLibrary.startBackMusic();
}
private function rulesClick(e:MouseEvent):void{
trace("rulezzz");
rules.rules.visible = true;
isWasRules = true;
}
public function onRetry(e:GameEvent):void{
trace(e.type);
MusicLibrary.startBackMusic();
startGameAfterRules();
}
override public function startGameClick(e:MouseEvent):void{
e.target.removeEventListener(MouseEvent.CLICK, startGame);
startGame();
}
private function onClickSoundOn(e:MouseEvent):void{
MusicLibrary.changeMute();
rules.soundOnBut.visible = false;
rules.soundBut.visible = true;
}
private function rulesClickClose(e:MouseEvent):void{
rules.rules.visible = false;
}
private function onClickSoundOff(e:MouseEvent):void{
MusicLibrary.changeMute();
rules.soundOnBut.visible = true;
rules.soundBut.visible = false;
}
override public function removeRules():void{
if (rules.parent == this){
removeChild(rules);
};
}
override public function startGame():void{
startGameAfterRules();
}
private function showLeaders(e:MouseEvent):void{
}
private function startGameAfterRules(e:MouseEvent=null):void{
var i:int;
while (i < numChildren) {
removeChildAt(0);
i++;
};
var gameGfx:GameGfx = new GameGfx();
var game:Game = new Game(gameGfx);
game.addEventListener(GameEvent.THEEND, onShowEndPage);
game.addEventListener(GameEvent.TIMEOUT, onShowEndPage);
addChild(game);
}
override public function onShowEndPage(e:GameEvent):void{
trace(e.type);
MusicLibrary.stopBackMusic();
var endGame:EndGamePage = new EndGamePage(e.score, e.time, e.type, candystand);
endGame.addEventListener(GameEvent.RETRY, onRetry);
addChild(endGame);
}
override public function showRules():void{
leaders = new LoaderGfx();
stage.addChild(leaders);
rules = new RulesGfx();
rules.rules.visible = false;
rules.startBut.addEventListener(MouseEvent.CLICK, startGameClick);
rules.rulesBut.addEventListener(MouseEvent.CLICK, rulesClick);
rules.submitBut.addEventListener(MouseEvent.CLICK, submitClick);
rules.rules.closeBut.addEventListener(MouseEvent.CLICK, rulesClickClose);
rules.moreGamesBut.addEventListener(MouseEvent.CLICK, moreGamesClick);
addChild(rules);
}
private function waitConnected(e:Event):void{
}
private function moreGamesClick(e:MouseEvent):void{
var url:String = "http://www.candystand.com/play/all-games";
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_blank");
}
private function submitClick(e:MouseEvent):void{
candystand.game.score = 0;
candystand.game.submitScore();
}
}
}//package
Section 72
//MainPreloader (MainPreloader)
package {
import com.greenish.onlinegames.*;
public class MainPreloader extends Preloader {
public function MainPreloader(){
super();
mochiId = "3f4a01786bbdf088";
}
}
}//package
Section 73
//MusicLibrary (MusicLibrary)
package {
import flash.media.*;
public class MusicLibrary {
public static var SubmitClass:Class = MusicLibrary_SubmitClass;
public static var isMute:Boolean = false;
public static var FlyClass:Class = MusicLibrary_FlyClass;
private static var music:Sound;
public static var BackClass:Class = MusicLibrary_BackClass;
public static var TimeoutClass:Class = MusicLibrary_TimeoutClass;
public static var BonusClass:Class = MusicLibrary_BonusClass;
private static var channel:SoundChannel;
public static var EndClass:Class = MusicLibrary_EndClass;
public function MusicLibrary(){
super();
}
public static function stopBackMusic():void{
channel.stop();
}
public static function playSound(sClass:Class, vol:Number=1):SoundChannel{
if (isMute){
vol = 0;
};
var music:Sound = new (sClass);
var sm:SoundChannel = music.play();
sm.soundTransform = new SoundTransform(vol);
return (sm);
}
public static function resume():void{
var vol:Number;
if (isMute){
vol = 0;
} else {
vol = 0.5;
};
music = new BackClass();
channel = music.play(0, 9999999);
channel.soundTransform = new SoundTransform(vol);
}
public static function pause():void{
stopBackMusic();
}
public static function changeMute():void{
isMute = !(isMute);
if (isMute){
channel.soundTransform = new SoundTransform(0);
} else {
channel.soundTransform = new SoundTransform(0.5);
};
}
public static function startBackMusic():void{
music = new BackClass();
channel = music.play(0, 9999999);
if (isMute){
channel.soundTransform = new SoundTransform(0);
} else {
channel.soundTransform = new SoundTransform(0.5);
};
}
}
}//package
Section 74
//MusicLibrary_BackClass (MusicLibrary_BackClass)
package {
import mx.core.*;
public class MusicLibrary_BackClass extends SoundAsset {
}
}//package
Section 75
//MusicLibrary_BonusClass (MusicLibrary_BonusClass)
package {
import mx.core.*;
public class MusicLibrary_BonusClass extends SoundAsset {
}
}//package
Section 76
//MusicLibrary_EndClass (MusicLibrary_EndClass)
package {
import mx.core.*;
public class MusicLibrary_EndClass extends SoundAsset {
}
}//package
Section 77
//MusicLibrary_FlyClass (MusicLibrary_FlyClass)
package {
import mx.core.*;
public class MusicLibrary_FlyClass extends SoundAsset {
}
}//package
Section 78
//MusicLibrary_SubmitClass (MusicLibrary_SubmitClass)
package {
import mx.core.*;
public class MusicLibrary_SubmitClass extends SoundAsset {
}
}//package
Section 79
//MusicLibrary_TimeoutClass (MusicLibrary_TimeoutClass)
package {
import mx.core.*;
public class MusicLibrary_TimeoutClass extends SoundAsset {
}
}//package
Section 80
//PauseGfx (PauseGfx)
package {
import flash.display.*;
public dynamic class PauseGfx extends MovieClip {
public var continueBut:SimpleButton;
public var blocker:SimpleButton;
}
}//package
Section 81
//PreloaderGfx (PreloaderGfx)
package {
import flash.display.*;
public dynamic class PreloaderGfx extends MovieClip {
public var progress:MovieClip;
}
}//package
Section 82
//RulesGfx (RulesGfx)
package {
import flash.display.*;
public dynamic class RulesGfx extends MovieClip {
public var rulesBut:SimpleButton;
public var moreGamesBut:SimpleButton;
public var rules:MovieClip;
public var submitBut:SimpleButton;
public var startBut:SimpleButton;
}
}//package
Section 83
//SliderGfx (SliderGfx)
package {
import flash.display.*;
public dynamic class SliderGfx extends MovieClip {
public var leftArrow:MovieClip;
public var rightArrow:MovieClip;
}
}//package