4DIS - FileEncryption

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 13: Line 13:
 
FileEncryption.EncryptFile ( "...url...", key as int );
 
FileEncryption.EncryptFile ( "...url...", key as int );
  
</javascript>
+
</syntaxhighlight>
  
 
----
 
----
Line 73: Line 73:
 
}
 
}
  
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

[edit] File encryption

4D IS - Back


FileEncryption is a class to encrypt files or strings.

Functions :

FileEncryption.Encrypt ( "...text...", key as int ) : String;
FileEncryption.EncryptFile ( "...url...", key as int );

You need ...

4DIS - IO

... and ...

FileEncryption.js

class FileEncryption
{
	public static function GetCharList ( string : String )
	{
		var s : String = "";
 
		for ( var i : int = 0; i < string.length; i++ )
			if ( s.IndexOf ( string [ i ] ) == -1 )
				s += string [ i ];
 
		return s;
	}
 
	public static function GetNewChar ( c : char, list : String, key : int )
	{
		var oi : int = list.length - list.IndexOf ( c ) - 1 + key;
 
		while ( oi >= list.length )
			oi -= list.length;
 
		while ( oi < 0 )
			oi += list.length;
 
		return list [ oi ];
	}
 
	public static function Encrypt ( string : String, key : int )
	{
		var list : String = GetCharList ( string );
		var rs : String = "";
 
		for ( var i : int = 0; i < string.length; i++ )
			rs += GetNewChar ( string [ i ], list, key );
 
		return rs;
	}
 
	public static function EncryptFile ( url : String, key : int )
	{
		if ( ! IO.ExistsFile ( url ) )
			return null;
 
		IO.WriteFile ( url, Encrypt ( IO.ReadFile ( url ), key ) );
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox