Strings in ActionScript

Type a sentence and press enter to create the cryptogram.

Get Adobe Flash player

function entry(e:KeyboardEvent):void{
	if(e.keyCode==13) {
	} //pressed enter
} //entry
function encrypt():void {
	var sub:String=shuffle(alph);
	var s:String=txtInput.text;
	var s2:String="";
	var i:int;
	for(i=0;i<s.length;i++) {
		var ch:String=s.charAt(i);
		var pos=alph.indexOf(ch); //is it a letter?
		if(pos>=0) //letter
		else s2+=ch; //other character
	}//loop to replace
function shuffle(s:String):String {
	var letters:Array=s.split(""); //make an array of the letters
	var i, j:int; 
	var temp:String; //when we swap two letters, we store one of them temporarily
	for(i=0;i<letters.length;i++) { //loop through the letters
		j=Math.random()*letters.length; //random letter
		while(j!=i && s.charAt(j)!=letters[j]) {
			j=Math.random()*letters.length; //try again
		} //get a replacement letter
		//swap letters i and j
		temp=letters[i]; //store letter[i]temporarily so it isn't erased in the next step 
		letters[i]=letters[j]; //replace letter[i] with letter[j]
		letters[j]=temp; //put former letter [i]from temp  into letter[j]
	} //loop to scramble
	var s2:String="";
	for(i=0;i<letters.length;i++) { //loop to make string2 from letters in array
		s2=s2+letters[i];  //concatenate with the +
	} //loop to concatenate the scrambled letters
	return s2;
} //shuffle
Download the movie.

NEXT: Text Files