Renamed CryptAffinity to cryptaffinity.

git-svn-id: https://websvn.glenux.net/svn/Upoc/cryptaffinity/trunk@1175 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
glenux 2009-01-18 20:48:28 +00:00
commit 8522e371bf
59 changed files with 3850 additions and 0 deletions

0
AUTHORS Normal file
View file

340
COPYING Normal file
View file

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

0
ChangeLog Normal file
View file

0
INSTALL Normal file
View file

3
Makefile.am Normal file
View file

@ -0,0 +1,3 @@
SUBDIRS = src
EXTRA_DIST = doc INSTALL README doxygen.conf autogen

0
NEWS Normal file
View file

0
README Normal file
View file

11
autogen Executable file
View file

@ -0,0 +1,11 @@
echo "libtoolize..."
libtoolize
echo "aclocal..."
aclocal
echo "autoheader..."
autoheader
echo "autoconf..."
autoconf
echo "automake..."
automake -a
echo "ok."

0
config.h.in Normal file
View file

172
configure.in Normal file
View file

@ -0,0 +1,172 @@
dnl Copyright (C) 2004-2005 Glenn ROLLAND.
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
dnl
## Autoconf requirements
AC_INIT([CryptAfinity], [0.2], [glenux@fr.st])
AC_PREREQ(2.50)
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([CryptAfinity],[0.2])
#AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(src/config.h)
AC_CONFIG_SRCDIR([src/lib/cryptafinity.hh])
AC_PROG_INSTALL
## information on the package
## ## checks for programs
## checks for libraries
## checks for header files
## checks for types
## checks for structures
## checks for compiler characteristics
## checks for library functions
## checks for system services
AM_CONFIG_HEADER(config.h)
## required for c sources
AC_ISC_POSIX
AC_PROG_CC
## required for c++ sources
AC_PROG_CXX
AC_PROG_CPP
# AC_PROG_RANLIB obsoleted bu LIBTOOL
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
# AC_PROG_YACC
# AC_PROG_LEX
# AM_PROG_LEX
dnl Checks for library functions.
AC_HEADER_STDC([])
#TODO: uncomment
AC_CHECK_HEADERS([vector set map iostream sstream string algorithm list memory iterator exception utility],,
AC_MSG_ERROR([You need to have the libstdc++ headers installed]))
dnl ***************************************************************************
dnl Gettext stuff.
dnl ***************************************************************************
#GETTEXT_PACKAGE=yalag-0.1
#AC_SUBST(GETTEXT_PACKAGE)
#AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.])
#ALL_LINGUAS="fr"
#AM_GLIB_GNU_GETTEXT
dnl Check for programs
dnl Check for build configuration.
#AC_PROG_INTLTOOL
AM_PROG_LIBTOOL
dnl Checks for header files.
#AC_MSG_NOTICE([checking presence of SQLite])
#AC_CHECK_HEADERS([sqlite.h],[],
# [
# AC_MSG_NOTICE([*** Please install/upgrade SQLite before proceeding])
# AC_MSG_NOTICE([*** with Unlost Memories installation.])
# AC_MSG_ERROR([cannot find sqlite.h])
# ])
#sqlite_deps="sqlite3 >= 3.0"
#PKG_CHECK_MODULES(SQLITE3,$sqlite_deps,build_sqlite=yes,build_sqlite=no)
#AC_SUBST(SQLITE3_CFLAGS)
#AC_SUBST(SQLITE3_LIBS)
glib_deps="glib-2.0 >= 2.0"
PKG_CHECK_MODULES(GLIB2,$glib_deps, build_glib=yes, build_glib=no)
AC_SUBST(GLIB2_CFLAGS)
AC_SUBST(GLIB2_LIBS)
##########
# Figure out where to get the READLINE header files.
#
AC_MSG_CHECKING([readline header files])
found=no
if test "$config_TARGET_READLINE_INC" != ""; then
TARGET_READLINE_INC=$config_TARGET_READLINE_INC
found=yes
fi
if test "$found" = "yes"; then
AC_MSG_RESULT($TARGET_READLINE_INC)
else
AC_MSG_RESULT(not specified: still searching...)
AC_CHECK_HEADER(readline.h, [found=yes])
fi
if test "$found" = "no"; then
for dir in /usr /usr/local /usr/local/readline /usr/contrib /mingw; do
AC_CHECK_FILE($dir/include/readline.h, found=yes)
if test "$found" = "yes"; then
TARGET_READLINE_INC="-I$dir/include"
break
fi
AC_CHECK_FILE($dir/include/readline/readline.h, found=yes)
if test "$found" = "yes"; then
TARGET_READLINE_INC="-I$dir/include/readline"
break
fi
done
fi
if test "$found" = "yes"; then
if test "$TARGET_READLINE_LIBS" = ""; then
TARGET_HAVE_READLINE=0
else
TARGET_HAVE_READLINE=1
fi
else
TARGET_HAVE_READLINE=0
fi
AC_SUBST(TARGET_READLINE_INC)
AC_SUBST(TARGET_HAVE_READLINE)
#libxml2_deps="libxml-2.0 >= 2.4.1"
#PKG_CHECK_MODULES(LIBXML2,$libxml2_deps, build_libxml2=yes, build_libxml2=no)
#AC_SUBST(LIBXML2_CFLAGS)
#AC_SUBST(LIBXML2_LIBS)
#if test $build_libxml2 == yes ; then
# AC_DEFINE(HAVE_LIBXML2_H,1,[Vaut 1 lorsque l'on utilise LIBXML2.])
#else
# AC_DEFINE(HAVE_LIBXML2_H,0,[Vaut 1 lorsque l'on utilise LIBXML2.])
#fi
#libxmlpp_deps="libxml++-2.6 >= 2.8"
#PKG_CHECK_MODULES(LIBXMLPP,$libxmlpp_deps, build_libxmlpp=yes, build_libxmlpp=no)
#AC_SUBST(LIBXMLPP_CFLAGS)
#AC_SUBST(LIBXMLPP_LIBS)
AC_CONFIG_FILES([Makefile src/Makefile src/lib/Makefile src/tools/Makefile ])
AC_OUTPUT
dnl configure.in ends here

33
doc/cryptafinity.css Normal file
View file

@ -0,0 +1,33 @@
/* Generated by CaScadeS, a stylesheet editor for Mozilla Composer */
p.code { border: 2px dashed rgb(153, 153, 153);
padding: 5px;
background: rgb(204, 204, 204) none repeat scroll 0% 50%;
-moz-background-clip: initial;
-moz-background-origin: initial;
-moz-background-inline-policy: initial;
font-family: monospace;
}
div.page { border: 2px dashed rgb(153, 153, 153);
padding: 10px;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
margin-right: auto;
margin-left: auto;
background-color: rgb(255, 255, 255);
opacity: 1;
width: 60%;
font-family: Arial,Helvetica,sans-serif;
}
body { background-color: rgb(51, 51, 51);
}
span.code { border: 1px dashed rgb(153, 153, 153);
background-color: rgb(204, 204, 204);
font-family: monospace;
}

430
doc/index.html Normal file
View file

@ -0,0 +1,430 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="fr-fr">
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<link rel="stylesheet" type="text/css" href="cryptafinity.css">
<title>MiniFTPc</title>
<meta content="Glenn ROLLAND" name="author">
</head>
<body style="direction: ltr;">
<div style="text-align: justify;" class="page code">
<h1>CryptAfinity</h1>
<ol>
<li><a href="#1._Description">Description</a></li>
<ol>
<li><a href="#1.1._Auteurs">Auteurs</a></li>
</ol>
<li><a href="#2._Pr%E9-requis">Pr&eacute;-requis</a></li>
<ol>
<li><a href="#2.1._Sur_un_syst%E8me_Debian_GNULinux">Sur un
syst&egrave;me Debian GNU/Linux</a></li>
<li><a href="#2.2._Sur_un_syst%E8me_Apple_MacOS_X_">Sur un
syst&egrave;me Apple MacOSX (&ge;10.3)</a></li>
<li><a href="#2.3._Sur_un_syst%E8me_Microsoft_Windows">Sur
un syst&egrave;me Microsoft Windows</a></li>
</ol>
<li><a href="#3._Se_procurer_MiniFTPc">Se procurer
CryptAfinity</a></li>
<li><a href="#4._Utiliser_MiniFTPc">Utiliser CryptAfinity</a></li>
<ol>
<li><a href="#4.1._Compilation">Compilation</a></li>
<li><a href="#4.2._Utilisation">Utilisation</a></li>
</ol>
<li><a href="#5._Documentation">Documentation</a></li>
</ol>
<h2><a name="1._Description"></a>1.
<a name="Description"></a>Description</h2>
<p>CryptAfinity est un logiciel
libre permettant de d&eacute;chiffrer des texte
obfusqu&eacute;s par des syst&egrave;mes Afines ou l'algorithme
de Vigen&egrave;re. Il poss&egrave;de les
caract&eacute;ristiques
suivantes :</p>
<ul>
<li>Il est distribu&eacute;
sous la licence&nbsp;<a href="http://www.gnu.org/copyleft/gpl.html">GNU
General Public License</a></li>
<li>Il est
&eacute;crit en C++.</li>
<li>Il
impl&eacute;mente
pour l'instant uniquement une analyse par fr&eacute;quences,
&agrave; partir d'une liste de "priorit&eacute;s" de lettres
dans un texte clair, et de la proportion que repr&eacute;sentent
les X premieres lettres "prioritaires" dans le texte.</li>
</ul>
<h3><span style="font-weight: bold;"></span>1.1.
Auteurs</h3>
<p>CryptAfinity a
&eacute;t&eacute; enti&egrave;rement
r&eacute;alis&eacute; par Glenn ROLLAND &lt;<a href="mailto:glenux@fr.st">glenux@fr.st</a>&gt;
&agrave; l'occasion de travaux pratiques du cours de syst&egrave;me du
Master 2 Ing&eacute;nierie Informatique -
Syst&egrave;mes, R&eacute;seaux et Internet.</p>
<h2><a name="2._Pr&eacute;-requis"></a>2.
Pr&eacute;-requis</h2>
<p>CryptAfinity
n&eacute;cessite les biblioth&egrave;ques de fonctions
suivantes (dans
leur version de d&eacute;veloppement si compilez le programme
vous-m&ecirc;me):</p>
<ul>
<li>glib-2.0</li>
</ul>
<h3><a name="2.1._Sur_un_syst&egrave;me_Debian_GNULinux"></a>2.1.
Sur un syst&egrave;me
Debian GNU/Linux</h3>
<p>Il vous suffit de taper (en
tant qu'administrateur) les
commandes suivantes pour installer le n&eacute;cessaire:&nbsp;</p>
<p class="code"># apt-get
install libglib-2.0-dev</p>
<h3><a name="2.2._Sur_un_syst&egrave;me_Apple_MacOS_X_"></a>2.2.
Sur un syst&egrave;me Apple MacOS X (&gt;= 10.3)</h3>
<p>
Il est n&eacute;cessaire d'avoir install&eacute; <span style="font-style: italic;"></span>les&nbsp;<span style="font-style: italic;">autotools</span>
(automake, autoconf...) dans leur derni&egrave;re
version.&nbsp;&Agrave; partir de l&agrave;, il suffit de
taper les commandes suivantes dans un terminal :</p>
<p class="code"># sudo fink
install glib2-dev</p>
<h3><a name="2.3._Sur_un_syst&egrave;me_Microsoft_Windows"></a>2.3.
Sur un syst&egrave;me Microsoft Windows</h3>
Cela ne fut pas (encore) test&eacute;, mais il est tr&egrave;s
probable que cela fonctionne&nbsp;sous Cygwin.<br>
<h2><a name="3._Se_procurer_MiniFTPc"></a>3.
Se procurer CryptAfinity</h2>
<p>
Vous
pouvez t&eacute;l&eacute;charger la derni&egrave;re archive
des
sources, ou bien directement la version la plus r&eacute;cente du
projet sur le d&eacute;p&ocirc;t Subversion du projet.</p>
<h3>3.1. L'archive des sources</h3>
<p>
Elle est disponible &agrave; l'adresse : </p>
<a href="http://glenux2.free.fr/pub/projets/CryptAfinity/archives/">http://glenux2.free.fr/pub/projets/CryptAfinity/archives/</a><br>
<h3>3.2. Le
d&eacute;p&ocirc;t Subversion</h3>
<p>Afin d'obtenir les sources les
plus &agrave; jour, vous pouvez utiliser le logiciel de
contr&ocirc;le de sources Subversion </p>
<p class="code">$ svn
checkout http://repository.glenux.ath.cx/svn/CryptAfinity/</p>
<p>Il n'y a pas de mot de passe,
il suffit donc de presser la touche
"Entr&eacute;e" pour l'utilisateur "anonymous", si ce dernier vous
est
demand&eacute;.</p>
<h2><a name="4._Utiliser_MiniFTPc"></a>4.
Utiliser CryptAfinity</h2>
<h3><a name="4.1._Compilation"></a>4.1.
Compilation</h3>
<p>Commencez par
d&eacute;compressez l'archive.</p>
<p class="code">$ tar -xzvf
CryptAfinity-0.1.tar.gz</p>
<p>Rendez vous ensuite dans le
dossier qui vient d'&ecirc;tre cr&eacute;&eacute; lors de
la d&eacute;compression.</p>
<p class="code">$ cd
CryptAfinity-0.2</p>
<p>Puis lancez
l'auto-configuration du logiciel, puis la compilation.</p>
<p class="code">$ ./autogen<br>
$ ./configure<br>
$ make</p>
<p>Le programme sous forme binaire
se trouvera alors dans le sous-dossier <span class="code">src/tools/</span>,
sous le nom <span class="code">break_afinity</span></p>
<h3><a name="4.2._Utilisation"></a>4.2.
Utilisation</h3>
<p>
CryptAfinity n&eacute;cessite de nombreux param&egrave;tres, avec la
syntaxe suivante:</p>
<p class="code">Usage:
break_afinity -a &lt;fichier&gt; -e &lt;float&gt; -f
&lt;float&gt; -p &lt;fichier&gt; -t
&lt;fichier&gt; -m <br>
</p>
<p>
O&ugrave; les param&egrave;tres sont les
suivants:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>-a, --alphabet
&lt;file&gt;&nbsp;</td>
<td>Fichier contenant les
lettres de l'alphabet, dans l'ordre.</td>
</tr>
<tr>
<td><br>
-e, --epsilon &lt;float&gt;</td>
<td>Tolerance pour le test
des clefs.</td>
</tr>
<tr>
<td>-f, --frequencies
&lt;float&gt;</td>
<td>Proportion moyenne que
repr&eacute;sentent les 9 lettres "prioritaires" dans le texte
clair.</td>
</tr>
<tr>
<td>-k, --keylength
&lt;int&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Taille de la clef
maximul (obsol&egrave;te)</td>
</tr>
<tr>
<td>-p, --priorities
&lt;file&gt;</td>
<td>Lettres
ordonn&eacute;es par fr&eacute;quence d&eacute;croissante
d'apparition dans le texte clair.</td>
</tr>
<tr>
<td>-t, --text
&lt;file&gt;</td>
<td>Fichier contenant le
texte chiffr&eacute;.</td>
</tr>
<tr>
<td>-m, --mode &lt;a|v&gt;</td>
<td>Selection du mode "Afine" ou "Vigen&egrave;re"</td>
</tr>
</tbody>
</table>
<h2><a name="5._Documentation"></a>5.
Documentation</h2>
<h3>5.1. Code</h3>
<p>Vous pouvez trouver la documentation du code de CryptAfinity dans le
dossier <span class="code">doc/html</span>
de l'application, ou en suivant <a href="html/index.html">ce lien</a>.</p>
<h3>5.2. Principe du "d&eacute;codeur Afine"</h3>
<p>On g&eacute;n&egrave;re l'espace des&nbsp;clefs possibles pour l'alphabet donn&eacute; en entr&eacute;e:</p>
<p class="code">int alpha_size; //taille de l'alphabet<br>
std::list&lt;int&gt; orb; // nombre premiers avec alpha_size<br>
MathTools mt; // bibliotheque d'outils math&eacute;matiques<br>
std::list&lt;KeyAfine&gt; keyList;<br>
std::list&lt;int&gt;::iterator orbIt;</p>
<p class="code">for (i=1; i&lt;alpha_size; i++){<br>
&nbsp;&nbsp;&nbsp; if (mt.pgcd(i, alpha_size) == 1) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; orb.push_back(i);<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
// 1 - g&eacute;n&eacute;rer l'espace des 312 clefs<br>
for (orbIt = orb.begin(); orbIt != orb.end(); orbIt++){<br>
&nbsp;&nbsp;&nbsp; KeyAfine key;<br>
&nbsp;&nbsp;&nbsp; key.setCoefA((*orbIt));<br>
&nbsp;&nbsp;&nbsp; for (i=0; i&lt;alpha_size; i++){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; key.setCoefB(i);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; keyList.push_back(key);<br>
&nbsp;&nbsp;&nbsp; }<br>
}</p>
<p>Puis on fait une attaque par analyse de fr&eacute;quence sur les textes
obtenus par "d&eacute;codage" du texte chiffr&eacute; avec les clefs essay&eacute;es.</p>
<p class="code">float frequencies; // fr&eacute;quence cumul&eacute;e des&nbsp;9 lettres les plus pr&eacute;sentes<br>
float epsilon; // marge d'erreur</p>
<p style="text-align: left;" class="code">std::list&lt;KeyAfine&gt;::iterator kLIt;<br>
for (kLIt = keyList.begin(); kLIt != keyList.end(); kLIt++){<br>
&nbsp;&nbsp;&nbsp; float score = 0;<br>
&nbsp;&nbsp;&nbsp; printf("Trying key %s\n", (*kLIt).toString().c_str());<br>
<br>
&nbsp;&nbsp;&nbsp; plainText = codec.decode(cypherText, *kLIt);&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; plainText.setAlphabet(this-&gt;_config.getAlphabet());<br>
&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;9; i++){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; score += plainText.getCountOf(prio_conf[i]);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; score = score / plainText.size();<br>
&nbsp;&nbsp;&nbsp; if (fabs(score - frequencies) &lt; epsilon){<br>
&nbsp; &nbsp; &nbsp; printf("KEY = %s\n",(*kLIt).toString().c_str());<br>
&nbsp; &nbsp; &nbsp;&nbsp;printf("PLAIN TEXT(%f) = %s\n", fabs(score-frequencies),<br>
&nbsp; &nbsp; &nbsp; &nbsp; plainText.toAlphabet().c_str());<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
}</p>
<h3>5.3. Principe du "d&eacute;codeur Vigen&egrave;re"</h3>
On commence par faire r&eacute;cup&eacute;rer les groupes de carat&egrave;res qui se r&eacute;p&egrave;tent dans le texte.<br>
<br>
Une fois obtenue plusieurs groupes de lettres, on regarde la distance
s&eacute;parrant les deux premiers groupes (note d1) puis la distance
entre les deux suivant (d2). Le PGCD de d1 et d2, doit donner un
multiple de la longueur de la clef. L'hypoth&egrave;se sous-jacente est
que ces groupes de lettres sont issue du chiffrement des m&ecirc;mes
bouts de mots avec les m&ecirc;mes bouts de la clef. Si le PGCD = 1 on
peut raisonnablement supposer que ce n'est pas le cas.<br>
<br>
L'&eacute;tape suivante consiste &agrave; faire une analyse de
fr&eacute;quence en d&eacute;coupant le texte en un nombre de colonne
correspondant au pgcd pr&eacute;c&eacute;demment calcul&eacute;. On
tire de cette analyse de fr&eacute;quence, un ordre de lettre par
importance. Puis en fonction de donn&eacute;es statistiques
pr&eacute;alables correspondant au contexte connu &agrave; prioris du
texte clair que l'on veut d&eacute;crypter, on essaie de faire
correspondre les lettres les plus souvent vu dans le texte avec le
mod&egrave;le de fr&eacute;quence.<br>
<br>
Ceci nous donne un ensemble de clef (r&eacute;duit &agrave; un ou pas), dans lequel se trouve normalement la bonne clef.<br>
</div>
</body>
</html>

1117
doxygen.conf Normal file

File diff suppressed because it is too large Load diff

2
src/Makefile.am Normal file
View file

@ -0,0 +1,2 @@
SUBDIRS = lib tools

38
src/lib/Makefile.am Normal file
View file

@ -0,0 +1,38 @@
SUBDIRS = .
lib_LTLIBRARIES = libcryptafinity.la
#bin_PROGRAMS = libulm.o
libcryptafinity_la_SOURCES = alphabet.cpp \
key.cpp \
text.cpp \
codec.cpp \
letter.cpp \
codec_afine.cpp \
codec_vigenere.cpp \
key_afine.cpp \
key_vigenere.cpp \
word_list.cpp \
math_tools.cpp \
freq_analyser.cpp
#libcryptafinity_la_SOURCES += cryptafinity_errors.hh \
# cryptafinity_global.hh \
# cryptafinity.hh \
# cryptafinity_iface.hh \
# cryptafinity_proto.hh \
# XSock.hh
libcryptafinity_la_CFLAGS = -DTRACE -static
libcryptafinity_la_LDFLAGS = -version-info 3:12:1
#INCLUDES= SQLITE3_CFLAGS@ \
# LIBXMLPP_CFLAGS@ \
# -I./
#libcryptafinity_a_LDFLAGS= @LDFLAGS@
#SQLITE3_LIBS@ LIBPCRE_LIBS@

31
src/lib/alphabet.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "alphabet.hh"
namespace LibCryptAfinity {
Alphabet::Alphabet() : std::vector<std::string>() { }
Alphabet::Alphabet(std::string alphaString) : std::vector<std::string>() {
int i;
std::string e;
for (i = 0; i < alphaString.length(); i++){
e.erase();
e+=alphaString[i];
this->push_back(e);
}
}
ReverseAlphabet Alphabet::getReverse() {
ReverseAlphabet ra;
int i;
std::string c;
for (i=0; i< this->size(); i++){
c = (*this)[i];
ra[c] = i;
//printf("%d->%s ",i,this->_alphabet[i].c_str());
}
//printf("\n");
return ra;
}
}

21
src/lib/alphabet.hh Normal file
View file

@ -0,0 +1,21 @@
#ifndef _LIBCRYPAFINITY_ALPHABET_HH
#define _LIBCRYPAFINITY_ALPHABET_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
class ReverseAlphabet: public std::map<std::string, int> {
};
class Alphabet : public std::vector<std::string> {
public:
Alphabet();
Alphabet(std::string alphaString);
ReverseAlphabet getReverse();
};
}
#endif

12
src/lib/codec.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "codec.hh"
namespace LibCryptAfinity {
Codec::Codec(){
}
Text Codec::encode(Text t, Key k) { }
Text Codec::decode(Text t, Key k) { }
}

22
src/lib/codec.hh Normal file
View file

@ -0,0 +1,22 @@
#ifndef _LIBCRYPAFINITY_CODEC_HH
#define _LIBCRYPAFINITY_CODEC_HH
#include "text.hh"
#include "key.hh"
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
class Codec {
private:
public:
Codec();
virtual Text encode(Text plaintext, Key key);
virtual Text decode(Text plaintext, Key key);
};
}
#endif

29
src/lib/codec_afine.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "codec_afine.hh"
#include "math_tools.hh"
namespace LibCryptAfinity {
CodecAfine::CodecAfine() : Codec() {
}
Text CodecAfine::decode(Text cypher, KeyAfine key){
Text result = cypher;
MathTools mt;
int i;
for (i=0; i<cypher.size(); i++){
// A must be the inverse of the real coefficient
result[i] = (mt.inverse(key.getCoefA(), cypher.getAlphabet().size()) * (cypher[i] + cypher.getAlphabet().size() - key.getCoefB()))
% cypher.getAlphabet().size();
}
return result;
}
Text CodecAfine::encode(Text plain, KeyAfine key){
Text result = plain;
int i;
for (i=0; i<plain.size(); i++){
result[i] = (plain[i] * key.getCoefA() + key.getCoefB()) % plain.getAlphabet().size();
}
return result;
}
}

23
src/lib/codec_afine.hh Normal file
View file

@ -0,0 +1,23 @@
#ifndef _LIBCRYPAFINITY_CODEC_AFINE_HH
#define _LIBCRYPAFINITY_CODEC_AFINE_HH
#include "codec.hh"
#include "key_afine.hh"
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
class CodecAfine : public Codec {
private:
public:
CodecAfine();
Text encode(Text t, KeyAfine k);
Text decode(Text t, KeyAfine k);
};
}
#endif

View file

@ -0,0 +1,51 @@
#include "codec_vigenere.hh"
namespace LibCryptAfinity {
CodecVigenere::CodecVigenere() : Codec() {
}
Text CodecVigenere::decode(Text t, KeyVigenere k){
Text result = t;
int txt_idx;
int key_idx;
int i;
int alpha_size = t.getAlphabet().size();
for (txt_idx=0; txt_idx<t.size(); txt_idx+=k.size()){
for (key_idx = 0; key_idx < k.size(); key_idx++) {
i = txt_idx + key_idx;
if (i < t.size()){
int cypher = result[i];
int key = k[key_idx];
int plain = (cypher + alpha_size - key) % (alpha_size);
result[i] = plain;
}
}
}
return result;
}
Text CodecVigenere::encode(Text t, KeyVigenere k){
Text result;
int txt_idx;
int key_idx;
int i;
int alpha_size = t.getAlphabet().size();
for (txt_idx=0; txt_idx<t.size(); txt_idx+=k.size()){
for (key_idx = 0; key_idx < k.size(); key_idx++) {
i = txt_idx + key_idx;
if (i < t.size()){
int plain = result[i];
int key = k[key_idx];
int cypher = (plain + key) % (alpha_size);
result[i] = cypher;
}
}
}
return result;
}
}

21
src/lib/codec_vigenere.hh Normal file
View file

@ -0,0 +1,21 @@
#ifndef _LIBCRYPAFINITY_CODEC_VIGENERE_HH
#define _LIBCRYPAFINITY_CODEC_VIGENERE_HH
#include "codec.hh"
#include "key_vigenere.hh"
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
class CodecVigenere : public Codec {
private:
public:
CodecVigenere();
Text encode(Text t, KeyVigenere k);
Text decode(Text t, KeyVigenere k);
};
}
#endif

8
src/lib/cryptafinity.hh Normal file
View file

@ -0,0 +1,8 @@
#ifndef _CRYPTAFINITY_HH
#define _CRYPTAFINITY_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
#include "cryptafinity_proto.hh"
#endif

View file

@ -0,0 +1,21 @@
#ifndef _CRYPTAFINITY_GLOBAL_HH
#define _CRYPTAFINITY_GLOBAL_HH
#include <stdio.h>
#include <list>
#include <vector>
#include <string>
#include <map>
#define COLOR_GREEN "\x1B[33m"
#define COLOR_NORMAL "\x1B[0m"
#ifndef pDEBUG
#define pDEBUG(x,...) if (DEBUG){ \
printf("%s:%d/ %s",x,__LINE__,COLOR_GREEN); \
printf(__VA_ARGS__); \
printf("%s",COLOR_NORMAL); \
}
#endif
#endif

View file

@ -0,0 +1,4 @@
#ifndef _CRYPTAFINITY_IFACE_HH
#define _CRYPTAFINITY_IFACE_HH
#endif

View file

@ -0,0 +1,14 @@
#ifndef _CRYPTAFINITY_PROTO_HH
#define _CRYPTAFINITY_PROTO_HH
#include "math_tools.hh"
#include "alphabet.hh"
#include "text.hh"
#include "key.hh"
#include "key_vigenere.hh"
#include "freq_analyser.hh"
#include "codec.hh"
#include "codec_vigenere.hh"
#include "codec_afine.hh"
#endif

36
src/lib/freq_analyser.cpp Normal file
View file

@ -0,0 +1,36 @@
#include "freq_analyser.hh"
#define DEBUG 0
namespace LibCryptAfinity {
std::list<TextCounter> FreqAnalyser::getPriorities(Text text, int keylen, int column){
std::list<TextCounter> result;
std::map<Text, int> counter;
std::map<Text, int>::iterator countIt;
int i;
for (i=0; i<text.size(); i += keylen) {
Text letter;
letter.push_back(text[i+column]);
if (counter.find(letter) == counter.end()){
counter[letter] = 1;
} else {
counter[letter] = counter[letter] + 1;
}
}
// on relit le map et on crée la liste...
pDEBUG("FreqAnaliser","Column %d\n", column);
for (countIt = counter.begin(); countIt != counter.end(); countIt++){
TextCounter tc;
tc.setText(countIt->first);
tc.setCount(countIt->second);
pDEBUG("FreqAnalyser"," Letter %s found %d times\n",tc.getText().toString().c_str(), tc.getCount());
result.push_back(tc);
}
result.sort();
result.reverse();
return result;
}
}

19
src/lib/freq_analyser.hh Normal file
View file

@ -0,0 +1,19 @@
#ifndef _LIBCRYPTAFINITY_FREQANALYSER_HH
#define _LIBCRYPTAFINITY_FREQANALYSER_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
#include "text.hh" // body
namespace LibCryptAfinity {
class FreqAnalyser {
private:
public:
std::list<TextCounter> getPriorities(Text t, int keylen, int column);
};
}
#endif

8
src/lib/key.cpp Normal file
View file

@ -0,0 +1,8 @@
#include "key.hh"
namespace LibCryptAfinity {
Key::Key() { }
// std::string Key::toString() { }
}

20
src/lib/key.hh Normal file
View file

@ -0,0 +1,20 @@
#ifndef _CRYPTAFINIY_KEY_HH
#define _CRYPTAFINIY_KEY_HH
//#include "text.hh"
//#include "cryptafinity_global.hh"
//#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
class Key {
private:
public:
Key();
//std::string toString();
};
}
#endif

38
src/lib/key_afine.cpp Normal file
View file

@ -0,0 +1,38 @@
#include "key_afine.hh"
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
int KeyAfine::getCoefA(){
return this->_a;
}
int KeyAfine::getCoefB(){
return this->_b;
}
void KeyAfine::setCoefA(int i){
this->_a = i;
}
void KeyAfine::setCoefB(int i){
this->_b = i;
}
std::string KeyAfine::toString(){
std::string s;
s="( ";
char * c= new char[200];
sprintf(c,"%d",this->_a);
s+=c;
s+=", ";
sprintf(c,"%d",this->_b);
s+=c;
s+=")";
return s;
}
}

27
src/lib/key_afine.hh Normal file
View file

@ -0,0 +1,27 @@
#ifndef _CRYPTAFINIY_KEYAFINE_HH
#define _CRYPTAFINIY_KEYAFINE_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
#include "key.hh" // declaration
#include "text.hh" // body
namespace LibCryptAfinity {
class KeyAfine : public Key {
private:
int _a;
int _b;
public:
void setCoefA(int i);
void setCoefB(int i);
int getCoefA();
int getCoefB();
std::string toString();
};
}
#endif

14
src/lib/key_vigenere.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "key_vigenere.hh"
namespace LibCryptAfinity {
KeyVigenere::KeyVigenere() : Key(), Text() { // Key()
int i;
i=0;
}
/* KeyVigenere::toString() {
Text *t = this;
this->toString();
} */
}

19
src/lib/key_vigenere.hh Normal file
View file

@ -0,0 +1,19 @@
#ifndef _CRYPTAFINIY_KEYVIGENERE_HH
#define _CRYPTAFINIY_KEYVIGENERE_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
#include "text.hh"
#include "key.hh"
namespace LibCryptAfinity {
class KeyVigenere : public Key, public Text {
private:
public:
KeyVigenere();
};
}
#endif

17
src/lib/letter.cpp Normal file
View file

@ -0,0 +1,17 @@
#include "letter.hh"
namespace LibCryptAfinity {
Letter::Letter(const Letter &orig){
this->_alphabet = orig._alphabet;
}
Alphabet Letter::getAlphabet() {
return this->_alphabet;
}
void Letter::setAlphabet(Alphabet alpha) {
this->_alphabet = alpha;
}
}

22
src/lib/letter.hh Normal file
View file

@ -0,0 +1,22 @@
#ifndef _LIBCRYPTAFINITY_LETTER_HH
#define _LIBCRYPTAFINITY_LETTER_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
#include "alphabet.hh"
namespace LibCryptAfinity {
class Letter {
private:
Alphabet _alphabet;
int _value;
public:
Letter(const Letter &orig);
Alphabet getAlphabet();
void setAlphabet(Alphabet alpha);
};
}
#endif

114
src/lib/math_tools.cpp Normal file
View file

@ -0,0 +1,114 @@
#include "math_tools.hh"
#define DEBUG 1
namespace LibCryptAfinity {
int MathTools::pgcd(int a, int b){
int fa = a;
int fb = b;
int pgcd;
int rest;
int tmp;
while(b > 0){
if (a<b){ tmp = a; a=b; b=tmp; }
rest = a%b;
//pDEBUG("MathTools::pgcd","%d - %d -> %d\n", a,b,rest);
a = b;
b = rest;
}
pDEBUG("MathTools::pgcd","%d - %d -> %d\n", fa,fb,a);
return a;
}
int MathTools::ppcm(int a, int b){
}
std::vector<int> MathTools::pgcd_real(int * reste, int * quotient, int * coef_first, int * coef_second, int pas){
std::vector<int> result;
int nreste = reste[0] % reste[1];
int nquotient;
int ncf, ncs; // coef first , coef sec
if (nreste == 0){
result.push_back(reste[1]);
if (pas % 2 == 0) {
result.push_back(coef_first[1]);
result.push_back(-coef_second[1]);
} else {
result.push_back(-coef_first[1]);
result.push_back(coef_second[1]);
}
return result;
} else {
nquotient = reste[1] / nreste;
ncf = quotient[1] * coef_first[1] + coef_first[0];
ncs = quotient[1] * coef_second[1] + coef_second[0];
reste[0] = reste[1];
reste[1] = nreste;
quotient[0] = quotient[1];
quotient[1] = nquotient;
coef_first[0] = coef_first[1];
coef_first[1] = ncf;
coef_second[0] = coef_second[1];
coef_second[1] = ncs;
return pgcd_real(reste, quotient, coef_first, coef_second, pas+1);
}
}
std::vector<int> MathTools::pgcd_mod(int a, int b){
int reste[2];
int quotient[2];
int coef_first[2];
int coef_second[2];
int i;
//init
reste[0] = a;
reste[1] = b;
quotient[0] = 0;
quotient[1] = a / b;
coef_first[0] = 1;
coef_first[1] = 0;
coef_second[0] = 0;
coef_second[1] = 1;
return this->pgcd_real(reste, quotient, coef_first, coef_second, 1);
}
int MathTools::inverse(int a, int modulo){
std::vector<int> pgcd_vec;
int ca, cm, cpgcd;
pgcd_vec = this->pgcd_mod(a, modulo);
ca = pgcd_vec[1];
cm = pgcd_vec[2];
cpgcd = pgcd_vec[0];
if (cpgcd != 1) {
// crash
pDEBUG("MathTools::inverse","CRASHHHHHH");
} else {
while (ca < 0){
ca = (ca + modulo);
}
// ca est positif;
ca = ca % modulo;
}
return ca;
}
}
#undef DEBUG

23
src/lib/math_tools.hh Normal file
View file

@ -0,0 +1,23 @@
#ifndef _LIBCRYPTAFINITY_MATHTOOLS_HH
#define _LIBCRYPTAFINITY_MATHTOOLS_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
namespace LibCryptAfinity {
class MathTools {
private:
std::vector<int> MathTools::pgcd_real(int * reste, int * quotient, int * coef_first, int * coef_second, int pas);
public:
int pgcd(int a, int b);
int ppcm(int a, int b);
std::vector<int> MathTools::pgcd_mod(int a, int b);
int MathTools::inverse(int a, int modulo);
};
}
#endif

186
src/lib/text.cpp Normal file
View file

@ -0,0 +1,186 @@
#include "text.hh"
#define DEBUG 0
namespace LibCryptAfinity {
bool TextCounter::operator< (TextCounter b){
fflush(stdout);
if (this->_text.size() < b.getText().size()){
return true;
} else if (this->_text.size() == b.getText().size()) {
// cas de l'egalité des tailles
if (this->_count < b.getCount()){
return true;
} else {
return false;
}
} else {
// cas du suppérieur
return false;
}
}
void TextCounter::setText(Text t){
this->_text = t;
}
int Text::getCountOf(int c){
int counter =0;
int i;
for (i=0; i<this->size(); i++){
if ((*this)[i] == c) {
counter++;
}
}
return counter;
}
Text TextCounter::getText(){
return this->_text;
}
void TextCounter::setCount(int i){
this->_count = i;
}
int TextCounter::getCount(){
return this->_count;
}
void TextCounter::setParam(std::list <int> param){
this->_param = param;
}
std::list<int> TextCounter::getParam(){
return this->_param;
}
Text::Text(Alphabet alphabet) : std::vector<int>() , _alphabet(alphabet) {
// vide au début
}
Text::Text() : std::vector<int>() {
// vide au début
}
void Text::setAlphabet(Alphabet alpha) {
this->_alphabet = alpha;
}
Alphabet Text::getAlphabet() { return this->_alphabet; }
void Text::append(std::string str){
}
std::list<TextCounter> Text::getRepeatedPatterns(){
// on découpe en patterns de 2 à texte / 3
std::list<TextCounter> result;
int patternsize;
int txt_idx;
int pat_idx;
bool pattern_active;
bool * active = new bool[this->size()];
for (txt_idx=0; txt_idx < this->size(); txt_idx++){
active[txt_idx] = true;
}
pDEBUG("Text::getRepeatedPatterns","getRepeatedPatterns\n");
int max_patternsize = (this->size() / 3);
for (patternsize=max_patternsize; patternsize>1; patternsize--){
std::map<Text, int> counter;
std::map<Text, std::list<int> > referencer;
for (txt_idx = 0; txt_idx < this->size()-patternsize; txt_idx++){
pattern_active = true;
Text currentword;
for (pat_idx = 0; pat_idx<patternsize; pat_idx++){
if (!active[txt_idx+pat_idx]){ pattern_active=false; }
currentword.push_back((*this)[txt_idx+pat_idx]);
}
if (pattern_active){
if (counter.find(currentword) == counter.end()){
//printf(" + defining new word..."); fflush(stdout);
counter[currentword] = 1;
referencer[currentword].push_back(txt_idx);
//printf(" done.\n");
} else {
counter[currentword] = counter[currentword]+1;
referencer[currentword].push_back(txt_idx);
pDEBUG("Text::getRepeatedPatterns","patternsize = %d , incrementing word %s to %d at %d ...",
patternsize,
currentword.toString().c_str(),
referencer[currentword].size(),
txt_idx);
fflush(stdout);
// on désactive les case trouvées
std::list<int> refs = referencer[currentword];
std::list<int>::iterator refsIt;
for(refsIt=refs.begin(); refsIt!=refs.end(); refsIt++){
for (pat_idx=0; pat_idx<patternsize; pat_idx++){
// printf("deactivating %d\n",(*refsIt)+pat_idx);
active[(*refsIt)+pat_idx]=false;
}
}
if (DEBUG) { printf(" done.\n"); }
}
} // end "if pattern_active
}
// pour chaque mots ajouté,
std::map<Text, int>::iterator counterIt;
for (counterIt=counter.begin();
counterIt!=counter.end();
counterIt++){
// si la freq est > 1; on l'ajoute a la liste des
// mots doublons, avec la freq...
if (counterIt->second > 1) {
TextCounter tc;
tc.setText(counterIt->first);
tc.setCount(counterIt->second);
tc.setParam(referencer[counterIt->first]);
result.push_back(tc);
}
}
}
printf("out\n");
result.sort();
result.reverse();
return result;
}
Text Text::substr(int index, int len){
Text result;
int i;
for (i=index; i<index+len; i++){
result.push_back((*this)[i]);
}
return result;
}
std::string Text::toAlphabet(){
int i;
std::string s;
s+="<< ";
char * c = new char[1024];
for (i=0; i<this->size(); i++){
s+=this->_alphabet[(*this)[i]];
}
free(c);
s+=">>";
return s;
}
std::string Text::toString(){
int i;
std::string s;
s+="[ ";
char * c = new char[1024];
for (i=0; i<this->size(); i++){
sprintf(c, "%d ", (*this)[i]);
s+=c;
}
free(c);
s+="]";
return s;
}
}
#undef DEBUG

56
src/lib/text.hh Normal file
View file

@ -0,0 +1,56 @@
#ifndef _LIBCRYPAFINITY_TEXT_HH
#define _LIBCRYPAFINITY_TEXT_HH
#include "cryptafinity_global.hh"
#include "cryptafinity_iface.hh"
#include "alphabet.hh"
namespace LibCryptAfinity {
class TextCounter;
class Text : public std::vector<int> {
private:
Alphabet _alphabet;
ReverseAlphabet _reverse_alphabet;
public:
Text();
Text(Alphabet alphabet);
void setAlphabet(Alphabet alpha);
Alphabet getAlphabet();
// on considere le texte comme
void append(std::string str);
Text substr(int start, int len);
std::string toString();
std::string toAlphabet();
int getCountOf(int c);
std::list<TextCounter> getRepeatedPatterns();
};
class TextCounter {
private:
Text _text;
int _count;
std::list<int> _param;
public:
void setText(Text t);
Text getText();
void setCount(int c);
int getCount();
void setParam(std::list<int> param);
std::list<int> getParam();
bool operator< (TextCounter b);
};
}
#endif

42
src/lib/word_list.cpp Normal file
View file

@ -0,0 +1,42 @@
#include "word_list.hh"
namespace LibCryptAfinity {
std::map<Text,int> WordList::getWordsContaining(int value){
std::map<Text,int> result;
std::map<int, TextCounter>::iterator foundVal;
while ((foundVal = this->_letter2wordnref.find(value))
!= this->_letter2wordnref.end()) {
printf("Ajouter mot/ref aux result\n");
}
return result;
}
void WordList::addWord(Text t, int ref, int len){
int i;
printf("addWord %s : %d : %d -> ", t.toString().c_str(), ref, len);
fflush(stdout);
std::map<Text, int>::iterator foundVal;
foundVal = this->_word2int.find(t);
// 1- verifier que le mot n'existe pas déja
// s'il existe, abandonner
if (foundVal != this->_word2int.end()){
printf("old\n");
// le mot existe déja, on laisse tomber alors;
} else {
printf("new\n");
// le mot n'existe pas, on l'ajoute alors...
this->_word2int[t]=1;
// 2- pour toute lettre du mot, créer l'association
// lettre => (mot, position_dans_le_mot);
for (i=0; i<t.size(); i++){
TextCounter tc;
tc.setText(t);
tc.setCount(i);
printf(" + %d -> (%s, %d)\n", t[i], t.toString().c_str(), i);
this->_letter2wordnref[t[i]]=tc;
}
}
}
}

21
src/lib/word_list.hh Normal file
View file

@ -0,0 +1,21 @@
#ifndef _CRYPTAFINIY_WORDLIST_HH
#define _CRYPTAFINIY_WORDLIST_HH
#include <map>
#include "text.hh"
namespace LibCryptAfinity {
class WordList {
private:
std::map<Text, int> _word2int; // existance du mot
std::map<int, TextCounter> _letter2wordnref;
public:
// texte, reference dans le texte global, longueur
void addWord(Text t, int ref, int len);
// retourne les mots qui contiennent le caractere choisi
std::map<Text,int> getWordsContaining(int val);
};
}
#endif

1
src/runAfine.sh Executable file
View file

@ -0,0 +1 @@
./tools/break_afinity -a tests/alphabet.txt -f 0.7 -m a -p tests/priority.txt -t tests/afine.txt -e 0.1

1
src/runVigenere.sh Executable file
View file

@ -0,0 +1 @@
./tools/break_afinity -a tests/alphabet.txt -f 0.7 -m v -p tests/priority.txt -t tests/vigenere.txt -e 0.05

36
src/tools/Makefile.am Normal file
View file

@ -0,0 +1,36 @@
#AM_YFLAGS = -d -v
SUBDIRS = .
bin_PROGRAMS = break_afinity
break_afinity_SOURCES = main.cpp ba_cmd.cpp ba_config.cpp file_loader.cpp ba_vigenere.cpp ba_afine.cpp
# ftp_client.cpp \
# ftp_client_cmd.cpp \
# ftp_client_data.cpp \
# miniftp.cpp \
# server_msg.cpp
break_afinity_SOURCES += ba_cmd.hh breakafinity.hh breakafinity_global.hh breakafinity_iface.hh breakafinity_proto.hh file_loader.hh
# ftp_config.hh \
# miniftp_global.hh \
# miniftp.hh \
# miniftp_iface.hh \
# miniftp_proto.hh \
# server_msg.hh
INCLUDES= -I../lib/ -I./ @GLIB2_CFLAGS@ @TARGET_READLINE_INC@
#BUILT_SOURCES = source_parser.h source_lexer.cc
# LEXLIB@
# libyalag.la
# miniftpc_INCLUDE = a
break_afinity_LDADD = -lcryptafinity @GLIB2_LIBS@
break_afinity_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs

66
src/tools/ba_afine.cpp Normal file
View file

@ -0,0 +1,66 @@
#include <math.h>
#include "ba_cmd.hh"
#define DEBUG 1
namespace BreakAfinity {
void BreakAfinity::runAfine(){
MathTools mt;
CodecAfine codec;
FreqAnalyser fa;
Text cypherText = this->_config.getText();
Text plainText;
int i;
std::list<TextCounter> tc;
cypherText.setAlphabet(this->_config.getAlphabet());
int alpha_size = this->_config.getAlphabet().size();
std::vector<int> prio_conf = this->_config.getPriorities();
// générer l'orbite de 26
std::list<int> orb;
for (i=1; i<alpha_size; i++){
if (mt.pgcd(i, alpha_size) == 1) {
orb.push_back(i);
}
}
// 1 - générer l'espace des 312 clefs
std::list<KeyAfine> keyList;
std::list<int>::iterator orbIt;
for (orbIt = orb.begin(); orbIt != orb.end(); orbIt++){
KeyAfine key;
key.setCoefA((*orbIt));
for (i=0; i<alpha_size; i++){
key.setCoefB(i);
keyList.push_back(key);
}
}
// on a la liste des clefs...
// on va tester les frequences...
std::list<KeyAfine>::iterator kLIt;
for (kLIt = keyList.begin(); kLIt != keyList.end(); kLIt++){
float score = 0;
printf("Trying key %s\n", (*kLIt).toString().c_str());
plainText = codec.decode(cypherText, *kLIt);
plainText.setAlphabet(this->_config.getAlphabet());
for (int i=0; i<9; i++){
score += plainText.getCountOf(prio_conf[i]);
}
score = score / plainText.size();
if (fabs(score - this->_config.getFrequencies()) < this->_config.getEpsilon()){
printf(" KEY = %s\n",(*kLIt).toString().c_str());
printf(" PLAIN TEXT(%f) = %s\n",fabs(score-0.7),plainText.toAlphabet().c_str());
}
}
return ;
}
}
#undef DEBUG

95
src/tools/ba_cmd.cpp Normal file
View file

@ -0,0 +1,95 @@
#include <math.h>
#include "ba_cmd.hh"
#define DEBUG 0
namespace BreakAfinity {
BreakAfinity::BreakAfinity(){
// on fixe la config par defaut
int i;
i=i+1;
}
void BreakAfinity::loadFiles(){
printf("ALIVE !!!\n");
this->_config.loadFiles();
printf("ALIVE ???\n");
}
void BreakAfinity::init(int argc, char **argv) {
int i;
for (i = 1; i + 1 < argc; i = i + 2){
char * opt = argv[i]; //GOOD
char * val = argv[i+1]; //GOOD
if ( (strcmp(opt, "--alphabet") == 0) || (strcmp(opt,"-a") == 0) ){
this->_config.setAlphabetFile(val);
continue;
}
if ( (strcmp(opt, "--epsilon") == 0) || (strcmp(opt,"-e") == 0) ){
this->_config.setEpsilon(atof(val));
continue;
}
if ( (strcmp(opt, "--priorities") == 0) || (strcmp(opt,"-p") == 0) ){
this->_config.setPrioritiesFile(val);
continue;
}
if ( (strcmp(opt, "--frequencies") == 0) || (strcmp(opt,"-f") == 0) ){
this->_config.setFrequencies(atof(val)); //File(val);
continue;
}
if ( (strcmp(opt, "--text") == 0) || (strcmp(opt,"-t") == 0) ){
this->_config.setTextFile(val);
continue;
}
if ( (strcmp(opt, "--mode") == 0) || (strcmp(opt,"-m") == 0) ){
this->_config.setMode(val);
continue;
}
/*
printf("Option = %s, ",argv[i]);
printf("value = %s\n",argv[i+1]);
*/
}
if (!this->_config.areParamReady())
{
printf("\nUsage: %s <options>\n", argv[0]);
printf("\nWhere options could be:\n");
printf("-a, --alphabet <file> Letters ordered by decreasing frequency\n");
printf("-e, --epsilon <float> Tolerance for the final key test\n");
printf("-f, --frequencies <float> Average frequencies for the 9 first letters\n");
printf("-m, --mode ( v | a ) Choose the kind of cypher : vigenere or afine.\n");
printf("-p, --priorities <file> Letters ordered by decreasing frequency\n");
printf("-t, --text <file> Cipher text to decipher\n");
//printf("-s, --popsize <int> Population size in each generation\n");
exit(-1);
} else {
printf("continuing...");
}
}
void BreakAfinity::run(){
// vigenere ou affine ?
MathTools mt;
CodecVigenere codec;
FreqAnalyser fa;
Text cypherText = this->_config.getText();
Text plainText;
std::list<TextCounter> tc;
cypherText.setAlphabet(this->_config.getAlphabet());
int alpha_size = this->_config.getAlphabet().size();
printf("Alive ==\n");
if (this->_config.isModeVigenere()){
printf("Selecting Vigenere mode\n");
this->runVigenere();
} else {
printf("Selecting Afine mode\n");
this->runAfine();
}
}
}
#undef DEBUG

27
src/tools/ba_cmd.hh Normal file
View file

@ -0,0 +1,27 @@
#ifndef _BREAKAFINITY_CMD_HH
#define _BREAKAFINITY_CMD_HH
#include <string.h>
#include <list>
#include "breakafinity.hh"
#include "ba_config.hh"
namespace BreakAfinity {
class BreakAfinity {
private:
BreakerConfig _config;
public:
BreakAfinity();
void init(int argc, char ** argv);
void loadFiles();
void run();
void runAfine();
void runVigenere();
};
}
#endif

169
src/tools/ba_config.cpp Normal file
View file

@ -0,0 +1,169 @@
#include "ba_config.hh"
#include "file_loader.hh"
namespace BreakAfinity {
void BreakerConfig::setMode(char * m){
switch(m[0]){
case 'v':
case 'V':
this->_modeVigenere = true;
break;
case 'a':
case 'A':
this->_modeVigenere = false;
break;
default:
this->_modeVigenere = true;
break;
}
}
bool BreakerConfig::isModeVigenere(){
return this->_modeVigenere;
}
BreakerConfig::BreakerConfig(){
this->_key_length = -1;
this->_modeVigenere = true;
}
Alphabet BreakerConfig::getAlphabet(){
return this->_alphabet;
}
void BreakerConfig::setFrequencies(float f){
this->_frequencies = f;
}
float BreakerConfig::getFrequencies(){
return this->_frequencies;
}
void BreakerConfig::setEpsilon(float e){
this->_epsilon = e;
}
float BreakerConfig::getEpsilon(){
return this->_epsilon;
}
bool BreakerConfig::areParamReady(){
printf("Testing parameters\n");
if ( (this->_text_file.length() > 0)
/* && (this->_frequencies_file.length() > 0) */
&& (this->_priorities_file.length() > 0)
&& (this->_alphabet_file.length() > 0)
&& (this->_epsilon > 0) && (this->_epsilon < 1)
) {
printf("Param OK !\n");
return true; }
else {
return false;
}
}
void BreakerConfig::loadFiles(){
FileLoader filo;
printf("Loading alphabet..."); fflush(stdout);
this->_alphabet = filo.loadAlphabet(this->_alphabet_file);
printf("Building reverse alphabet...\n"); fflush(stdout);
this->_reverse_alphabet = this->_alphabet.getReverse();
printf("Loading text..."); fflush(stdout);
this->_text = filo.loadText(this->_reverse_alphabet,
this->_text_file);
printf("Loading priorities..."); fflush(stdout);
this->_priorities = filo.loadPriorities(this->_reverse_alphabet,
this->_priorities_file);
//printf("Loading frequencies..."); fflush(stdout);
//this->_frequencies = filo.loadFrequencies(
// this->_reverse_alphabet,
// this->_frequencies_file);
}
void BreakerConfig::setTextFile(std::string filename){
if (filename.length()<1){
printf("Error: incorrect text file name '%s'",filename.c_str());
} else {
printf("Text file = %s\n", filename.c_str());
this->_text_file = filename;
}
}
std::string BreakerConfig::getTextFile(){
return this->_text_file;
}
void BreakerConfig::setAlphabetFile(std::string filename){
if (filename.length()<1){
printf("Error: incorrect alphabet file name '%s'",filename.c_str());
} else {
printf("Alphabet file = %s\n", filename.c_str());
this->_alphabet_file = filename;
}
}
std::string BreakerConfig::getAlphabetFile(){
return this->_alphabet_file;
}
/*
void BreakerConfig::setFrequenciesFile(std::string filename){
if (filename.length()<1){
printf("Error: incorrect frequencies file name '%s'",filename.c_str());
} else {
printf("Frequencies file = %s\n", filename.c_str());
this->_frequencies_file = filename;
}
}*/
/* std::string BreakerConfig::getFrequenciesFile(){
return this->_frequencies_file;
} */
void BreakerConfig::setPrioritiesFile(std::string filename){
if (filename.length()<1){
printf("Error: incorrect priorities file name '%s'",filename.c_str());
} else {
printf("Priorities file = %s\n", filename.c_str());
this->_priorities_file = filename;
}
}
std::string BreakerConfig::getPrioritiesFile(){
return this->_priorities_file;
}
void BreakerConfig::setKeyLength(int len){
if (len < 1){
printf("Error: incorrect key length '%d'",len);
} else {
printf("Key length = %d\n", len);
this->_key_length = len;
}
}
Text BreakerConfig::getText(){
return this->_text;
}
std::vector<int> BreakerConfig::getPriorities(){
return this->_priorities;
/*
std::list<TextCounter> result;
std::map<int,int>::iterator prioIt;
for (prioIt = this->_priorities.begin();
prioIt != this->_priorities.end();
prioIt++){
TextCounter tc;
result.push_back(tc); //FIXME: fill the tc
}
return result;*/
}
}

74
src/tools/ba_config.hh Normal file
View file

@ -0,0 +1,74 @@
#ifndef _BREAKAFINITY_CONFIG_HH
#define _BREAKAFINITY_CONFIG_HH
#include <string>
#include <vector>
#include <map>
#include "alphabet.hh"
#include "text.hh"
using namespace LibCryptAfinity;
namespace BreakAfinity {
class BreakerConfig {
private:
bool _modeVigenere;
int _key_length;
std::string _alphabet_file;
std::string _text_file;
std::string _frequencies_file;
std::string _priorities_file;
float _epsilon;
Alphabet _alphabet;
std::map<std::string, int> _reverse_alphabet;
Text _text;
//std::map<int, float> _frequencies;
float _frequencies;
std::vector<int> _priorities;
public:
BreakerConfig();
bool areParamReady();
void setEpsilon(float e);
float getEpsilon();
void setAlphabetFile(std::string);
std::string getAlphabetFile();
// void setFrequenciesFile(std::string);
// std::string getFrequenciesFile();
void setPrioritiesFile(std::string);
std::string getPrioritiesFile();
void setTextFile(std::string);
std::string getTextFile();
void loadFiles();
void reverseAlphabet();
void setKeyLength(int len);
int getKeyLength();
void setMode(char * c);
bool isModeVigenere();
Alphabet getAlphabet();
float getFrequencies();
void setFrequencies(float f);
std::vector<int> getPriorities();
Text getText();
};
}
#endif

128
src/tools/ba_vigenere.cpp Normal file
View file

@ -0,0 +1,128 @@
#include <math.h>
#include "ba_cmd.hh"
#define DEBUG 0
namespace BreakAfinity {
void BreakAfinity::runVigenere(){
MathTools mt;
CodecVigenere codec;
FreqAnalyser fa;
Text cypherText = this->_config.getText();
Text plainText;
std::list<TextCounter> tc;
cypherText.setAlphabet(this->_config.getAlphabet());
int alpha_size = this->_config.getAlphabet().size();
// 1 - repérer les mots qui se répentent
pDEBUG("BreakAfinity::run","analysing %s\n",cypherText.toString().c_str());
KeyVigenere key;
TextCounter fst;
TextCounter sec;
int dist1, dist2;
int fst_idx1, fst_idx2;
int sec_idx1, sec_idx2;
int key_len;
int key_idx;
tc = cypherText.getRepeatedPatterns();
fst = tc.front();
tc.pop_front();
sec = tc.front();
std::list<int> fst_idx = fst.getParam();
std::list<int> sec_idx = sec.getParam();
fst_idx1 = fst_idx.front();
fst_idx.pop_front();
fst_idx2 = fst_idx.front();
sec_idx1 = sec_idx.front();
sec_idx.pop_front();
sec_idx2 = sec_idx.front();
dist1 = fst_idx2 - fst_idx1;
dist2 = sec_idx2 - sec_idx1;
// 2 - on en déduit la longueur de la clef
key_len = mt.pgcd(dist1,dist2);
pDEBUG("BreakAfinity::run","PGCD(%d, %d) = %d\n", dist1, dist2, key_len);
// 3 - on calcule le décalage par colonne
std::list<TextCounter>::iterator pI;
std::vector<int> prio_conf = this->_config.getPriorities();
for (int i=0; i< prio_conf.size(); i++){
printf("%d - ",prio_conf[i]);
}
printf("\n");
std::list<KeyVigenere> keyList;
std::list<KeyVigenere>::iterator lI;
for (key_idx = 0; key_idx < key_len; key_idx++){
std::list<TextCounter> prio_list;
TextCounter firstCypherTC, firstPlainTC;
int firstCypher, firstPlain;
int shift;
prio_list = fa.getPriorities(cypherText, key_len, key_idx);
firstCypherTC = prio_list.front();
firstCypher = firstCypherTC.getText()[0];
std::list<KeyVigenere> nList;
for (int i=0; i<2; i++){
firstPlain = prio_conf[i];
//printf("Shift column %d from %d to %d\n",
//key_idx,
//firstCypher,
//firstPlain);
//
// on fixe le décalage a partir de la premiere priorité...
shift = (alpha_size + firstCypher - firstPlain) % alpha_size;
// Cypher = Plain + Key => Key = Cypher - Plain
if(key_idx==0){
KeyVigenere kv;
kv.push_back(shift);
nList.push_back(kv);
} else {
for (lI=keyList.begin(); lI!=keyList.end(); lI++){
KeyVigenere kv=*lI;
//printf("From %s ",kv.toString().c_str());
kv.push_back(shift);
//printf("creating %s\n",kv.toString().c_str());
nList.push_back(kv);
}
}
}
keyList.clear();
for (lI=nList.begin(); lI!=nList.end(); lI++){
keyList.push_back((*lI));
}
}
// on filtre en fonction des 70%...
for (lI=keyList.begin(); lI!=keyList.end(); lI++){
float score = 0;
key = (*lI);
printf("Trying key %s\n", key.toString().c_str());
plainText = codec.decode(cypherText, key);
plainText.setAlphabet(this->_config.getAlphabet());
for (int i=0; i<9; i++){
score += plainText.getCountOf(prio_conf[i]);
}
score = score / plainText.size();
if (fabs(score - this->_config.getFrequencies()) < this->_config.getEpsilon()){
key.setAlphabet(this->_config.getAlphabet());
printf(" KEY = %s\n",key.toAlphabet().c_str());
printf(" PLAIN TEXT(%f) = %s\n",fabs(score-0.7),plainText.toAlphabet().c_str());
}
}
return ;
}
}
#undef DEBUG

View file

@ -0,0 +1,8 @@
#ifndef _BREAKAFINITY_HH
#define _BREAKAFINITY_HH
#include "breakafinity_global.hh"
#include "breakafinity_iface.hh"
#include "breakafinity_proto.hh"
#endif

View file

@ -0,0 +1,21 @@
#ifndef _BREAKAFINITY_GLOBAL_HH
#define _BREAKAFINITY_GLOBAL_HH
#include <stdio.h>
#include <stdlib.h>
#include "cryptafinity.hh"
#define COLOR_GREEN "\x1B[33m"
#define COLOR_NORMAL "\x1B[0m"
#ifndef pDEBUG
#define pDEBUG(x,...) if (DEBUG){ \
printf("%s:%d/ %s",x,__LINE__,COLOR_GREEN); \
printf(__VA_ARGS__); \
printf("%s",COLOR_NORMAL); \
}
#endif
#endif

View file

@ -0,0 +1,4 @@
#ifndef _BREAKAFINITY_IFACE_HH
#define _BREAKAFINITY_IFACE_HH
#endif

View file

@ -0,0 +1,8 @@
#ifndef _BREAKAFINITY_PROTO_HH
#define _BREAKAFINITY_PROTO_HH
#include "ba_cmd.hh"
#include "ba_config.hh"
#include "ba_config.hh"
#endif

97
src/tools/file_loader.cpp Normal file
View file

@ -0,0 +1,97 @@
#include "file_loader.hh"
using namespace LibCryptAfinity;
namespace BreakAfinity {
std::vector<int> FileLoader::loadPriorities(
std::map<std::string, int> reverse_alpha,
std::string filename){
std::vector<int> result;
std::vector<std::string> file;
int i;
file = this->loadFile(filename);
printf("PRIORITIES = "); fflush(stdout);
for (i=0; i<file.size(); i++){
printf("%d->%s ", i, file[i].c_str());
result.push_back(reverse_alpha[file[i]]); //]=i;
}
printf("\n");
return result;
}
std::map<int, float> FileLoader::loadFrequencies(
std::map<std::string, int> reverse_alpha,
std::string filename){
std::map <int, float> result;
std::vector<std::string> file;
int i;
file = this->loadFile(filename);
printf("FREQUENCIES = "); fflush(stdout);
for (i=0; i<file.size(); i++){
printf("%s ", file[i].c_str());
}
printf("\n");
return result;
}
std::vector<std::string> FileLoader::loadFile(std::string filename){
gchar * contentc;
gsize length;
GError *error = NULL;
std::vector<std::string> result;
std::string contents;
std::string sub;
int lf_idx;
g_file_get_contents(filename.c_str(),
&contentc,
&length,
&error);
contents = contentc;
while((lf_idx = contents.find("\n")) != std::string::npos){
sub = contents.substr(0, lf_idx);
//printf("%s",sub.c_str());
contents.erase(0,lf_idx+1);
result.push_back(sub);
}
return result;
}
Alphabet FileLoader::loadAlphabet(std::string filename){
std::vector<std::string> file;
Alphabet result;
file = this->loadFile(filename);
int i;
printf("ALPHABET = "); fflush(stdout);
for (i=0; i<file.size(); i++){
printf("%s",file[i].c_str());
result.push_back(file[i]);
}
printf("\n");
return result;
}
Text FileLoader::loadText(
std::map<std::string,int> reverse_alpha,
std::string filename){
Text result;
std::vector<std::string> file;
int i;
int txtidx;
file = this->loadFile(filename);
printf("TEXT = "); fflush(stdout);
for (i=0; i<file.size(); i++){
printf("%s",file[i].c_str());
std::string s = file[i];
for (txtidx = 0; txtidx< s.length(); txtidx++){
std::string letter;
letter += s[txtidx];
result.push_back(reverse_alpha[letter]);
}
}
printf("\n");
return result;
}
}

36
src/tools/file_loader.hh Normal file
View file

@ -0,0 +1,36 @@
#include <string>
#include <list>
#include <vector>
#include <map>
#include <glib.h>
#include <glib/gfileutils.h>
#include "alphabet.hh"
#include "text.hh"
using namespace LibCryptAfinity;
namespace BreakAfinity{
class FileLoader {
private:
public:
std::vector<int> loadPriorities(
std::map<std::string, int> reverse_alpha,
std::string filename);
std::map<int, float> loadFrequencies(
std::map<std::string, int> reverse_alpha,
std::string filename);
std::vector<std::string> loadFile(std::string filename);
Alphabet loadAlphabet(std::string filename);
Text loadText(
std::map<std::string,int > reverse_alpha,
std::string filename);
};
}

14
src/tools/main.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "breakafinity.hh"
#include "ba_cmd.hh"
using namespace BreakAfinity;
int main(int argc, char ** argv){
BreakAfinity::BreakAfinity br_af;
br_af.init(argc, argv);
br_af.loadFiles();
br_af.run();
return EXIT_SUCCESS;
}