flash on 2010-5-5
/**
* Copyright kihon ( http://wonderfl.net/user/kihon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ce34
*/
package
{
import com.bit101.components.NumericStepper;
import com.bit101.components.PushButton;
import com.bit101.components.TextArea;
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
private var srcArea:TextArea;
private var destArea:TextArea;
private var stepper:NumericStepper;
public function Main()
{
srcArea = new TextArea(this, 0, 0, "FLASH");
destArea = new TextArea(this, 0, 0);
srcArea.width = destArea.width = stage.stageWidth;
srcArea.height = 100;
stepper = new NumericStepper(this, 150, srcArea.height + 10);
stepper.value = 3;
new PushButton(this, 0, srcArea.height + 10, "Encryption", onClick);
destArea.y = stepper.y + 50;
destArea.height = stage.stageHeight - destArea.y;
onClick();
}
private function onClick(event:Event = null):void
{
destArea.text = shift(srcArea.text, stepper.value);
}
private function shift(src:String, key:int):String
{
var table:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var dest:String = "";
for (var i:int = 0; i < src.length; i++)
{
var char:String = src.charAt(i);
var pos:int = table.indexOf(char);
pos += key;
pos %= 26;
if (pos < 0) pos += 26;
dest += table.charAt(pos);
}
return dest;
}
}
}