src/metroidCodeBreaker.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
pageTitle="metroid . code . breaker"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:xx="nu.xero.flex.*"
backgroundColor="#000000" backgroundAlpha="1"
backgroundImage="@Embed(source='assets/metpassbg.png')"
applicationComplete="init()"
width="763" height="571"
layout="absolute">
<mx:Style>
@font-face {
src: url("assets/narpassword00000.fixed.width.[fontvir.us].ttf");
fontFamily: narpassword00000fixedwidth;
fontWeight: normal;
}
@font-face {
src: url("assets/narpassword00000.[fontvir.us].ttf");
fontFamily: narpassword00000regular;
fontWeight: normal;
}
.NARPASSWORD {
fontFamily: narpassword00000fixedwidth;
fontSize: 27;
}
.NARTITLE {
fontFamily: narpassword00000fixedwidth;
color: #4cdc48;
fontSize: 16;
}
.NARSMALL {
fontFamily: narpassword00000regular;
color: #3cbcfc;
fontSize: 12;
}
CheckBox {
fillColors: #cccccc, #666666, #cccccc, #999999;
borderColor: #ffffff;
color: #ffffff;
textSelectedColor: #ffffff;
textRollOverColor: #ffffff;
themeColor: #999999;
}
VScrollBar {
cornerRadius: 0;
fillAlphas: 0.6, 0.4, 0.75, 0.65;
fillColors: #333333, #666666, #333333, #cccccc;
trackColors: #333333, #666666;
themeColor: #4cdc48;
borderColor: #000000;
}
NumericStepper {
borderStyle: solid;
cornerRadius: 0;
fillColors: #333333, #666666, #333333, #cccccc;
backgroundColor: #cccccc;
themeColor: #4cdc48;
fontFamily: Courier;
}
</mx:Style>
<mx:Script>
<![CDATA[
//____________________________________________________________
// importz
import mx.managers.*;
import mx.controls.*;
//____________________________________________________________
// varz
private var gamedata :Array;
private var num :Array;
private var bool :Array;
private var setup :Boolean;
private var value :Number;
private var now :Number;
private var i :Number;
private var j :Number;
//testing varz
private var getit :Array;
//____________________________________________________________
// constructor
private function init():void {
ToolTipManager.enabled = false;
gamedata = new Array(16);
for(i = 0; i < 16; i++){
gamedata[i] = new Array(8);
}
num = new Array(18);
bool = new Array(144);
//thePassword.setPass(new Array(23, 10, 27, 25, 10, 28, 28, 32, 24, 27, 13, 0, 0, 0, 0, 0, 63, 63, 63, 63, 63, 63, 63, 63));
thePassword.setPass(new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
decode(thePassword.getPass());
process();
thePassword.addEventListener(MouseEvent.CLICK, focusCode);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPress);
}
//____________________________________________________________
// decoder
private function decode(pass:Array):void {
for(i = 0; i < 24; i++) {
now = pass[i];
for(j = 5; j >= 0; j--) {
bool[6 * i + j] = now % 2 == 1;
now = Math.floor(now * .5);
}
}
for(i = 16; i < 18; i++) {
num[i] = 0;
for(j = 0; j < 8; j++) {
if(bool[8 * i +j]) {
num[i] = num[i] + Math.pow(2, 7 - j);
}
}
}
now = num[16] % 128;
bool = bool.slice(now, 128).concat(bool.slice(0, now));
for(i = 0; i < 16; i++) {
for(j = 0; j < 8; j++) {
gamedata[i][j] = bool[8 * i + 7 - j];
}
}
}
//____________________________________________________________
// encoder
private function encode():Array {
num[17] = num[16];
for(i = 0; i < 16; i++) {
for(j = 0; j < 8; j++) {
if(gamedata[i][j]) {
num[17] = num[17] + Math.pow(2, j);
}
}
}
num[17] = num[17] % 256;
theOptions.num17.value = num[17];
for(i = 0; i < 16; i++) {
for(j = 0; j < 8; j++) {
bool[8 * i + 7 - j] = gamedata[i][j];
}
}
now = num[16] % 128;
bool = bool.slice(128 - now, 128).concat(bool.slice(0, 128 - now));
for(i = 16; i < 18; i++) {
now = num[i];
for(j = 7; j >= 0; j--) {
bool[8 * i + j] = now % 2 == 1;
now = Math.floor(now * .5);
}
}
var newpass:Array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
for(i = 0; i < 24; i++) {
for(j = 0; j < 6; j++) {
if(bool[6 * i + j]) {
newpass[i] = newpass[i] + Math.pow(2, 5 - j);
}
}
}
return newpass;
}
//____________________________________________________________
// sync form
private function process():void {
value = 0;
for(i = 0; i < 16; i++) {
if(i == 10) {
i = 14;
}
for(j = 0; j < 8; j++) {
if(i == 8 && j < 4) {
j = 4;
}
setup = (gamedata[i][j]==0)?(false):(true);
this.theOptions["chk" + j + i]["selected"] = setup;
}
}
for(i = 8; i < 14; i++){
if(i == 9) {
i = 10;
}
num[i] = 0;
for(j = 0; j < 8; j++) {
if(gamedata[i][j]) {
num[i] = num[i] + Math.pow(2, j);
}
if(i == 8 && j > 2) {
j = 8;
}
}
}
theOptions.num8.value = num[8];
theOptions.num10.value = num[10];
theOptions.num11.value = num[11] + 256 * num[12] + 65536 * num[13];
theOptions.num16.value = num[16];
}
//____________________________________________________________
// unsync form
private function unprocess():void {
for(i = 0; i < 16; i++) {
if(i == 10) {
i = 14;
}
for(j = 0; j < 8; j++) {
if(i == 8 && j < 4) {
j = 4;
}
//value = (this.theOptions["chk" + i + j]["selected"]==true)?(1):(0);
gamedata[i][j] = this.theOptions["chk" + j + i]["selected"];
}
}
value = theOptions.num8.value;
for(i = 8; i < 14; i++) {
if(i == 9) {
i = 10;
value = theOptions.num10.value;
}
if(i == 11) {
value = theOptions.num11.value;
}
for(j = 0; j < 8; j++) {
gamedata[i][j] = value % 2 == 1;
value = Math.floor(value * .5);
if(i == 8 && j > 2) {
j = 8;
}
}
}
num[16] = theOptions.num16.value;
}
//____________________________________________________________
// random code
private function randomPass():void {
for(i = 0; i < 16; i++) {
if(i == 10) {
i = 14;
}
for(j = 0; j < 8; j++) {
if(i == 8 && j < 4) {
j = 4;
}
setup = (randomizer(0, 1)==1)?(true):(false);
this.theOptions["chk" + j + i]["selected"] = setup;
}
}
theOptions.num8.value = randomizer(0, 5); ////// THIS IS 5 or 15??? TEST!!!
theOptions.num10.value = randomizer(0, 256);
theOptions.num11.value = randomizer(0, 16777216);
theOptions.num16.value = randomizer(0, 256);
}
//____________________________________________________________
// make random code
public function makeRandomPass():void {
randomPass();
unprocess();
thePassword.setPass(encode());
process();
}
//____________________________________________________________
// generate code
public function generate():void {
unprocess();
thePassword.setPass(encode());
process();
}
//____________________________________________________________
// mouse handeler
private function focusCode(e:MouseEvent):void {
thePassword.getCodeFocus();
}
//____________________________________________________________
// key handeler
private function keyPress(e:KeyboardEvent):void {
if(thePassword.hasFocus){
switch(e.keyCode){
case 37:
thePassword.moveLeft();
break;
case 39:
thePassword.moveRight();
break;
}
}
}
//____________________________________________________________
// randomizer
private function randomizer (low:Number, high:Number):Number {
return Math.floor(low + (Math.random() * (high-low)));
}
]]>
</mx:Script>
<xx:options id="theOptions" x="261.5" y="150" height="256" width="244"/>
<xx:theCode id="thePassword" x="201.5" y="467"/>
</mx:Application>