Crypt::FNA
Version 0.56
FNA stands for Fractal Numerical Algorithm, the symmetrical encryption method based on two algorithms that I developed for: 1. the construction of a family of fractal curves (F) 2. a encryption based on these curves.
A precise description of this algorithm is covered by Article on http://www.perl.it/documenti/articoli/2010/04/anakryptfna.html
my $krypto=Crypt::FNA->new( { r=> '8', angle => [56,-187,215,64], square => 4096, background => [255,255,255], foreground => [0,0,0], magic => 2, salted => 'true' } ); my $krypto2=Crypt::FNA->new();
Shows the depth in the calculation of the curve. It 's a number greater than zero, not necessarily integer. Indicated by the number of corners Ro basis of self-similar structure, the number of segments forming the curve is given by Ro**r.
Default value: 7
Are the angles covered by the recursion algorithm: these angles determines the basic structure self-similar curve (F). Angles are expressed in sessadecimal system, with values ranging from -360 And 360 (ie from 0 to 360).
Default value: (56, -187, 215, -64)
It 's the length of the side of a square container of the curve. Square has not only important for the (If any) graphical representation, but also for encryption, because it is used to calculate the length of the side of the curve (the square is proportional to ro r **)
Default: 4096
And 'the RGB color background PNG file containing the design curve. The notation is decimal, then with values ranging from 0 to 255.
Default value: (255,255,255)
And 'the RGB color tract in the PNG file containing the design curve. The notation is decimal, then with values ranging from 0 to 255.
Default value: (0,0,0)
Indicates the number of vertices of the curve to be skipped during encryption and decryption: Since the algorithm, a continuous function on the top, skipping some, this is still on top of all the isolated points (Hence "fair").
Default value: 3
The "salted" attribute, a boolean, instructs the class to use a cryptographic salt, so that multiple encryption the same data will, in general, different cryptogram.
Default value: false (for backward compatibility with previous versions of FNA)
See CONSTRUCTOR METHOD
encrypt_file decrypt_file method and are the sum: make it useful by applying the mathematical curves (F). This method carries out a very precise: it encrypt the input file to output file. The syntax is:
$krypto->encrypt_file($name_plain_file, $name_encrypted_file)
The input file of any format will be encrypt by the curve (F).
The methods and decrypt_file encrypt_file, are summa: make it useful by applying the mathematical curves (F). This method carries out a very precise: it decrypt the input file (which is to encrypt_file output method) in the output file (which is the input method encrypt_file).
The syntax is:
$krypto->decrypt_file($name_encrypted_file, $name_decrypted_file)
The input file is read and decoded through the curve (F), the output file.
The method encrypt_scalar digit strings: the result of encryption is a vector containing the cryptogram. The syntax is:
my @encrypted_scalar=$krypto->encrypt_scalar($this_scalar)
See examples
The method decrypt_scalar make a plain string from the encrypted array returned from encrypt_scalar method: the result of decryption is a scalar containing plain value. The syntax is:
@decrypted_scalar=$krypto->decrypt_scalar(@encrypted_scalar)
The MAC method, computes the digital signature of a file (FNA work how a digest algoritm). The signature is represented by the coordinates of the last vertex of the curve {F} used. The syntax is:
my $mac=$krypto->mac($name_plain_file)
This method is undoubtedly the most impressive and allows you to "touch" the curves that will be applied in cryptographic algorithms. For the programmer can be useful in your application, show the curve, for example, a hypothetical control panel for managing passwords or encrypted files in an attachment to forms sent by email and stored on the server.
The graphic file output format is PNG (Portable Network Graphic), accessible from any browser by as many different graphics software.
$krypto->make_fract($pngfile, $zoom)
1. $pngfile is the name of the png files - without extension "PNG" is inserted automatically 2. $zoom the drawing scale - greater than zero. Default value: 1
The image produced is contained in the square of side $square.
$krypto->make_fract('fractal1',1);
$krypto->encrypt_file('test.txt','test.fna');
$krypto->decrypt_file('test.fna','test_rebuild.txt');
$krypto->encrypt_file('test.txt','test2.fna'); $krypto2->encrypt_file('test2.fna','test3.fna'); $krypto2->decrypt_file('test3.fna','test2_rebuild.fna'); $krypto->decrypt_file('test2_rebuild.fna','test3_rebuild.txt');
my @encrypted_scalar=$krypto->encrypt_scalar('questa è una prova'); for(@encrypted_scalar) {print $_."\n"}
my $decrypted_scalar=$krypto->decrypt_scalar(@encrypted_scalar); print $decrypted_scalar;
$krypto->make_fract("fractal3","3a"); # nome file png e zoom my @errors=@{$krypto->message}; foreach my $errors(@errors) { print "> 1-".$errors."\n" } @errors=@{$krypto2->message}; foreach my $errors(@errors) { print "> 2-".$errors."\n" }
0 Order of the curve is not correct. Must necessarily be numeric. Ex. r=7 1 Order of the curve must be a number greater than 0 2 Length Square container is incorrect. Must necessarily be numeric 3 Side of a square container fractal must be a number greater than 0 5 Value of is not correct. Must necessarily be numeric.Default loaded 6 The angle must be expressed in the system sessadecimal (ex. 126.35) Default loaded 7 Error reading sub encrypt, package Crypt::FNA 8 error writing file, package Crypt::FNA sub encrypt 9 read error on sub decrypt myInput package Crypt::FNA 10 write error on sub decrypt MYOUTPUT package Crypt::FNA 11 error writing PNG sub draw_fract package Crypt::FNA 12 error background: only numeric character (RGB) 13 error background: only three number (RGB) from 0 to 255 14 error foreground: only numeric character (RGB) 15 error foreground: only three number (RGB) from 0 to 255 16 error loading GD::Simple, drawing aborted 18 error zoom: the value must be a number greater than zero 19 errors during object instantiation 20 error magic setting 21 error salted value (true or false only) 22 error loading Tie::File 23 Error reading sub mac, package Crypt::FNA"
The first we meet is "set_starting_angle" which, as already briefly mentioned, the system converts radiant angles passed from parent script, initializing the object (new method). Besides this method returns the number of angles under the curve (F), $ ro, data necessary to calculate otherwise be lost during the population of $ self-> angle than the carrier that re-initializes initial_angle @ $ self-> angle at the end of processing
Calculates the length of the side of the curve (F). This distance is used both in the processes of encryption (encrypt_file and encrypt_scalar) that reconstruction of the data ("decrypt_file"), as well as the drawing method (make_fract). The side of the curve, also as the distance traveled by the turtle in the design phase is a fundamental and structural, since they directly affect the coordinates of the vertices used by the various class methods FNA.
Is invoked by all methods (not "new") and calls the fundamental "evaluate_this_angle" as well as "evaluate_this_coords, calculating the angles and coordinates of the curve of its vertices. It 'a real ring junction in the recursive process.
Invoked from all encryption methods, if the "salted" attribute is true: return a cryptographic salt, long as the square of the magic number.
This method optimizes memory usage by FNA, reducing minimum directions to be stored in memory. For properties of {F}, given 'n' vertices and a given order 'r' of the curve, the number of directions strictly necessary for the calculation is given by Ro = n ** r -> r = log (n) / log (Ro)
calculates the angle of the segment k-th of the {F} curve
calculates the X and Y of the vertex k-th of the {F} curve
see Theory
Briefly, indicating therefore:
Ro -> number of parameters of the base (4 in the case of the Koch curve) r -> the order of the curve ann -> number of direction of the segments of the curve of order n
We can establish that the number of directions (n) curve of order n is:
ann = Ro**r
Here now the directions of various orders in a building in a triangle:
r=0 0 r=1 0, 60, -60, 0 r=2 0, 60, -60, 0, 60, 120, 0, 60, -60, 0, -120, -60, 0, 60, -60, 0
Reminds you of something? Note the similarity with the construction of the triangle Tartaglia:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
This triangle shows the triangular arrangement of binomial coefficients, ie the development of the binomial coefficients (a + b) raised to any exponent n.
The thing that interests us is that any number of the triangle is obtained as the sum of the two corresponding to the top line: note that we can express the properties of self-similarity of the Koch curve through a similar construction, combining the values of the base and then with those derived from the combination and so on iterating the procedure.
In this case, an ex. Ro = 4, we have this situation:
row for r = 0 -> 0 + 0 = 0 row for r = 1 -> 0 + 0 = 0 0 + 60 = 60, 0 to 60 = -60, 0 + 0 = 0 row for r = 2 -> I. 0+0=0 0+60=60 0-60=-60 0+0=0 II. 60+0=60 60+60=120 60-60=0 60+0=60 III. -60+0=-60 -60+60=0 -60-60=-120 -60+0=-60 IV. 0+0=0 0+60=60 0-60=-60 0+0=0
Repeating the procedure, we obtain precisely the angles of the curve of order n.
However, appear to identify the corners of the curve of order n is still necessary to identify all those angles with order <n We continue to see, writing a succession of directions as the elements of a vector:
a(0) = a(0) + a(0) a(1) = a(0) + a(1) GROUP I a(2) = a(0) + a(2) a(3) = a(0) + a(3) ------------------------------ a(4) = a(1) + a(0) a(5) = a(1) + a(1) GROUP II a(6) = a(1) + a(2) a(7) = a(1) + a(3) ------------------------------ a(8) = a(2) + a(0) a(9) = a(2) + a(1) GROUP III a(10)= a(2) + a(2) a(11)= a(2) + a(3) ------------------------------ a(12)= a(3) + a(0) a(13)= a(3) + a(1) GROUP IV a(14)= a(3) + a(2) a(15)= a(3) + a(3)
Thus we have the summations to identify the different angles of segments approximating the curve ... written reports in this way, we can clearly see the properties of the two addends that provide the angle n-th:
The first addendum is the group or the branch on which we iterate the construction. The second term is the location of which we are calculating in that branch.
The group that the k-th direction so we can indicate in the formalism of Perl:
G(k) = int(k/ro)
The location of the k-th direction its group is:
P(k) = k-int(k/Ro) = k*G(k)
Ultimately, the value of the k-th direction will be:
a(k) = a(G(k)) + a(P(k)) (1)
We note that this report is general, independent of the number of basic parameters of the curve. In one of Koch have a base of cardinality equal to 4 but is not necessarily so. With this relationship becomes straightforward to derive the graph of the curve, being able to calculate the angles at a certain order and then implementing a system of turtle for use:
while ($k<$Ro**$r) { $a[$k] = $a[int($k/$Ro)] + $a[$k-int($k/$Ro)]; $K++ }
Then we indicate with {F} the set of curves whose directions the segments are obtained by approximating the equation (1). {F} has a Hausdorff dimension between 1 and 2 (with small variations can be calculated even those with size less than 1, as Cantor dust) and infinite cardinality as easily detected by observing the number of parameters possible parent.
In short:
Each byte is encrypted using the coordinates of the top of fractal curve, obtained starting from the next than previously estimated, jumping a further number of vertices equal to the magic number plus the value of bytes to encrypt.
Follow the curve occurring fractal, from vertex to vertex, that the coordinates match those of the cryptogram. The value of the original byte is reconstructed having counted how many vertices have succeeded to get two values of equality, equality last met. The number of vertices, reduced the magic number added to the unit, represents the value of the n-th byte.
Mario Rossano software@netlogicalab.com software@netlogica.it http://www.netlogicalab.com
Please, send me your alerts to software@netlogica.it
Write me :) software@netlogica.it
FNA by Mario Rossano, http://www.netlogicalab.com
This pod text by Mario Rossano
Copyright (C) 2009 Mario Rossano aka Anak birthday 05/08/1970; birthplace: Italy
This program is free software; you can redistribute it and/or modify it under the terms of either: CC-NC-BY-SA license http://creativecommons.org/licenses/by-nc-sa/2.5/it/deed.en Creative Commons License: http://i.creativecommons.org/l/by-nc-sa/2.5/it/88x31.png
FNA Fractal Numerical Algorithm for a new cryptography technology, author Mario Rossano is licensed under a: http://creativecommons.org/B/by-nc-sa/2.5/it/deed.en - Creative Commons Attribution-Noncommercial-Share Alike 2.5 Italy License
Permissions beyond the scope of this license may be available at software@netlogicalab.com
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'è'. Assuming CP1252
To install Crypt::FNA, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Crypt::FNA
CPAN shell
perl -MCPAN -e shell install Crypt::FNA
For more information on module installation, please visit the detailed CPAN module installation guide.