4DIS - FileEncryption

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 10: Line 10:
 
<javascript>
 
<javascript>
  
FileEncryption.Encrypt ( "...text...", key as int );
+
FileEncryption.Encrypt ( "...text...", key as int ) : String;
 
FileEncryption.EncryptFile ( "...url...", key as int );
 
FileEncryption.EncryptFile ( "...url...", key as int );
  

Revision as of 21:48, 2 November 2011

File encryption

4D IS - Back


FileEncryption is a class to encrypt files or strings.

Functions :

<javascript>

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

</javascript>


You need ...

4DIS - IO

... and ...

FileEncryption.js

<javascript>

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 ) ); } }

</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox