summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/proflycee/tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-11-01 03:03:53 +0000
committerNorbert Preining <norbert@preining.info>2023-11-01 03:03:53 +0000
commita9d0083bcc66de9ea863ed14cf8cde44e88e4355 (patch)
tree318e4601d64ad18b02489d8569f62c8243849ee4 /macros/latex/contrib/proflycee/tex
parent8e5b71c9e0334c62d993c6d03d9a5a98ca59518b (diff)
CTAN sync 202311010303
Diffstat (limited to 'macros/latex/contrib/proflycee/tex')
-rw-r--r--macros/latex/contrib/proflycee/tex/ProfLycee.sty3
-rw-r--r--macros/latex/contrib/proflycee/tex/proflycee-tools-arithm.tex247
-rw-r--r--macros/latex/contrib/proflycee/tex/proflycee-tools-listings.tex16
3 files changed, 265 insertions, 1 deletions
diff --git a/macros/latex/contrib/proflycee/tex/ProfLycee.sty b/macros/latex/contrib/proflycee/tex/ProfLycee.sty
index e31dc6dca4..8a2c6fe812 100644
--- a/macros/latex/contrib/proflycee/tex/ProfLycee.sty
+++ b/macros/latex/contrib/proflycee/tex/ProfLycee.sty
@@ -3,7 +3,8 @@
% or later, see http://www.latex-project.org/lppl.txtf
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{ProfLycee}[2023/10/25 3.00b Aide pour l'utilisation de LaTeX en lycee]
+\ProvidesPackage{ProfLycee}[2023/10/27 3.00c Aide pour l'utilisation de LaTeX en lycee]
+% 3.00c Ajout de chiffrements (César + Affine + Hill)
% 3.00b Amélioration de la commande des intervalles (spécifier un label pour les bornes)
% 3.00a Ajout de commandes pour travailler avex des intervalles + Nouvelle numérotation
% 2.8.0 Amélioration du tapis de Sierpinski
diff --git a/macros/latex/contrib/proflycee/tex/proflycee-tools-arithm.tex b/macros/latex/contrib/proflycee/tex/proflycee-tools-arithm.tex
index 0085e0ee98..fcff96116f 100644
--- a/macros/latex/contrib/proflycee/tex/proflycee-tools-arithm.tex
+++ b/macros/latex/contrib/proflycee/tex/proflycee-tools-arithm.tex
@@ -672,4 +672,251 @@
}
}%
+%====CHIFFREMENTS !!
+\xdef\aLPHaBeTMajusc{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
+\xdef\aLPHaBeTminusc{abcdefghijklmnopqrstuvwxyz}
+
+\NewDocumentCommand\InverseModulo{ s m m }{%
+ \xdef\PGCDD{\xinteval{gcd(#2,#3)}}%
+ \xdef\resinvmod{#2{} n'est pas inversible modulo #3.}
+ \xintFor* ##1 in {\xintSeq{1}{#3}}\do{\xintifboolexpr{\xintiiRem{\xinteval{#2*##1}}{#3} == 1}{\xdef\resinvmod{##1}}{}}%
+ \IfBooleanTF{#1}%
+ {%
+ On a $\text{PGCD}(#2;#3)=\num{\PGCDD}$.~%
+ \xintifboolexpr{\PGCDD != 1}%
+ {Le PGCD étant différent de 1, on en déduit que #2 n'est pas inversible modulo #3.\relax}%
+ {Le PGCD étant égal à 1, on en déduit que #2 admet un inverse modulo #3.\\De plus on a $#2 \times \resinvmod = \xinteval{#2*\resinvmod} \equiv \xintiirem{\xinteval{#2*\resinvmod}}{#3}\:[#3]$, donc \resinvmod\ est l'inverse de #2 modulo #3.\relax}%
+ }%
+ {}%
+}
+
+\defKV[chiffaffine]{a=\xdef\tmpcoeffa{#1},b=\xdef\tmpcoeffb{#1},modulo=\xdef\tmpmodulo{#1}}
+\setKVdefault[chiffaffine]{a=3,b=12,Dechiffr=false,modulo=26}
+
+\NewDocumentCommand\ChiffrementAffine{ O{} m }{%
+ \restoreKV[chiffaffine]%
+ \setKV[chiffaffine]{#1}%
+ %pgcd stocké
+ \xdef\PGCDD{\xinteval{gcd(\tmpcoeffa,\tmpmodulo)}}%
+ \StrLen{#2}[\tmpnbcaract]%
+ \ifboolKV[chiffaffine]{Dechiffr}%
+ {%
+ \xdef\resinvmod{0}%
+ \xintFor* ##1 in {\xintSeq{1}{\tmpmodulo}}\do{
+ \xintifboolexpr{\xintiiRem{\xinteval{(\tmpcoeffa)*(##1)}}{\tmpmodulo} == 1}%
+ {\xdef\resinvmod{##1}}{}%
+ }%
+ }{}%
+ \foreach \i in {1,...,\tmpnbcaract}{%
+ \StrChar{#2}{\i}[\tmpchar]%
+ \IfStrEq{\tmpchar}{ }%
+ {~}%
+ {%
+ %majuscule minuscule
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchar}%
+ {%
+ \StrPosition{\aLPHaBeTMajusc}{\tmpchar}[\tmpcoeffx]%
+ }%
+ {%
+ \StrPosition{\aLPHaBeTminusc}{\tmpchar}[\tmpcoeffx]%
+ }%
+ \xdef\tmpcoeffx{\xinteval{\tmpcoeffx-1}}%
+ \ifboolKV[chiffaffine]{Dechiffr}%
+ {%
+ \xintifboolexpr{\PGCDD == 1}%
+ {%
+ \xdef\tmpres{\xintiiRem{\xinteval{(\resinvmod)*(\tmpcoeffx)-(\resinvmod)*(\tmpcoeffb)}}{\tmpmodulo}}%
+ \xdef\tmpres{\xinteval{\tmpres+1}}%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchar}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpres}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpres}%
+ }%
+ }%
+ {}%
+ }%
+ {%
+ \xdef\tmpres{\xintiiRem{\xinteval{\tmpcoeffa*\tmpcoeffx+\tmpcoeffb}}{\tmpmodulo}}%
+ \xdef\tmpres{\xinteval{\tmpres+1}}%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchar}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpres}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpres}%
+ }%
+ }%
+ }%
+ }%
+ \ifboolKV[chiffaffine]{Dechiffr}%
+ {\xintifboolexpr{\PGCDD != 1}{Le message ne peut pas être déchiffré car $\text{PGCD}(\tmpcoeffa;\tmpmodulo)\neq1$ !\relax}{}}%
+ {}%
+}
+
+\defKV[chiffhill]{Matrice=\xdef\tmpcoeffmat{#1},Modulo=\xdef\tmpmodulo{#1}}
+\setKVdefault[chiffhill]{Matrice={1,2,3,5},Dechiffr=false,modulo=26}
+
+\NewDocumentCommand\ChiffrementHill{ O{} m }{%
+ \restoreKV[chiffhill]%
+ \setKV[chiffhill]{#1}%
+ %passage de la châine en nb pair
+ \StrLen{#2}[\tmpnbcar]%
+ \xintifboolexpr{\xintiirem{\tmpnbcar}{2} == 1}{\xdef\tmpchaine{#2A}}{\xdef\tmpchaine{#2}}%
+ \StrLen{\tmpchaine}[\tmpnbblocs]%
+ \xdef\tmpnbblocs{\xintieval{\tmpnbblocs/2}}%
+ %extraction des coeffs de la matrice + déterminant
+ \readlist*\coeffmathill{\tmpcoeffmat}%
+ \itemtomacro\coeffmathill[1]{\tmpcoeffa}%
+ \itemtomacro\coeffmathill[2]{\tmpcoeffb}%
+ \itemtomacro\coeffmathill[3]{\tmpcoeffc}%
+ \itemtomacro\coeffmathill[4]{\tmpcoeffd}%
+ \xdef\detmathill{\xintieval{(\tmpcoeffa)*(\tmpcoeffd)-(\tmpcoeffb)*(\tmpcoeffc)}}%
+ %chiffrement / déchiffrement
+ \ifboolKV[chiffhill]{Dechiffr}%
+ {%
+ %le cas où la matrice n'est pas inversible
+ \xintifboolexpr{\detmathill == 0}%
+ {%
+ La matrice $\begin{pmatrix} \tmpcoeffa & \tmpcoeffb \\ \tmpcoeffc & \tmpcoeffd \end{pmatrix}$ n'est pas inversible, donc pas de déchiffrement possible !\relax
+ }%
+ {%
+ %inversibilité du déterminant
+ \xdef\resinvmod{0}%
+ \xintFor* ##1 in {\xintSeq{1}{\tmpmodulo}}\do{%
+ \xintifboolexpr{\xintiiRem{\xinteval{(\detmathill)*(##1)}}{\tmpmodulo} == 1}%
+ {\xdef\resinvmod{##1}}{}%
+ }%
+ \xintifboolexpr{\resinvmod == 0}%si det non inversible modulo
+ {%
+ Le déterminant de la matrice $\begin{pmatrix} \tmpcoeffa & \tmpcoeffb \\ \tmpcoeffc & \tmpcoeffd \end{pmatrix}$ (qui vaut $\detmathill$) n'est pas inversible modulo \tmpmodulo, donc pas de déchiffrement !\relax
+ }%
+ {%
+ %on peut déchiffrer !!
+ \foreach \i in {1,...,\tmpnbblocs}{%
+ \xdef\tmpindicea{\xintieval{2*(\i-1)+1}}\xdef\tmpindiceb{\xintieval{2*(\i)}}%
+ \StrChar{\tmpchaine}{\tmpindicea}[\tmpchara]%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchara}%
+ {%
+ \StrPosition{\aLPHaBeTMajusc}{\tmpchara}[\tmpcoeffx]%
+ }%
+ {%
+ \StrPosition{\aLPHaBeTminusc}{\tmpchara}[\tmpcoeffx]%
+ }%
+ \xdef\tmpcoeffx{\xintieval{\tmpcoeffx-1}}%
+ \StrChar{\tmpchaine}{\tmpindiceb}[\tmpcharb]%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpcharb}%
+ {%
+ \StrPosition{\aLPHaBeTMajusc}{\tmpcharb}[\tmpcoeffy]%
+ }%
+ {%
+ \StrPosition{\aLPHaBeTminusc}{\tmpcharb}[\tmpcoeffy]%
+ }%
+ \xdef\tmpcoeffy{\xintieval{\tmpcoeffy-1}}%
+ %1ère lettre
+ \xdef\tmpresa{\xintiiRem{\xintieval{(\resinvmod)*(\tmpcoeffd)*(\tmpcoeffx)-(\resinvmod)*(\tmpcoeffb)*(\tmpcoeffy)}}{\tmpmodulo}}%
+ \xdef\tmpresa{\xinteval{\tmpresa+1}}%
+ %2ème lettre
+ \xdef\tmpresb{\xintiiRem{\xintieval{-(\resinvmod)*(\tmpcoeffc)*(\tmpcoeffx)+(\resinvmod)*(\tmpcoeffa)*(\tmpcoeffy)}}{\tmpmodulo}}%
+ \xdef\tmpresb{\xinteval{\tmpresb+1}}%
+ %affichage des deux caractères
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchara}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpresa}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpresa}%
+ }%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpcharb}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpresb}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpresb}%
+ }%
+ }%
+ }%
+ }%
+ }%
+ {%
+ \foreach \i in {1,...,\tmpnbblocs}{%
+ \xdef\tmpindicea{\xintieval{2*(\i-1)+1}}\xdef\tmpindiceb{\xintieval{2*(\i)}}%
+ \StrChar{\tmpchaine}{\tmpindicea}[\tmpchara]%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchara}%
+ {%
+ \StrPosition{\aLPHaBeTMajusc}{\tmpchara}[\tmpcoeffx]%
+ }%
+ {%
+ \StrPosition{\aLPHaBeTminusc}{\tmpchara}[\tmpcoeffx]%
+ }%
+ \xdef\tmpcoeffx{\xintieval{\tmpcoeffx-1}}%
+ \StrChar{\tmpchaine}{\tmpindiceb}[\tmpcharb]%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpcharb}%
+ {%
+ \StrPosition{\aLPHaBeTMajusc}{\tmpcharb}[\tmpcoeffy]%
+ }%
+ {%
+ \StrPosition{\aLPHaBeTminusc}{\tmpcharb}[\tmpcoeffy]%
+ }%
+ \xdef\tmpcoeffy{\xintieval{\tmpcoeffy-1}}%
+ %1ère lettre
+ \xdef\tmpresa{\xintiiRem{\xintieval{(\tmpcoeffa)*(\tmpcoeffx)+(\tmpcoeffb)*(\tmpcoeffy)}}{\tmpmodulo}}%
+ \xdef\tmpresa{\xinteval{\tmpresa+1}}%
+ %2ème lettre
+ \xdef\tmpresb{\xintiiRem{\xintieval{(\tmpcoeffc)*(\tmpcoeffx)+(\tmpcoeffd)*(\tmpcoeffy)}}{\tmpmodulo}}%
+ \xdef\tmpresb{\xinteval{\tmpresb+1}}%
+ %affichage des deux caractères
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchara}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpresa}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpresa}%
+ }%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpcharb}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpresb}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpresb}%
+ }%
+ }%
+ }%
+}
+
+\defKV[chiffcesar]{Decal=\xdef\tmpdecalcesar{#1}}
+\setKVdefault[chiffcesar]{Decal=5,Dechiffr=false}
+
+\NewDocumentCommand\ChiffrementCesar{ O{} m }{%
+ \restoreKV[chiffcesar]%
+ \setKV[chiffcesar]{#1}%
+ \StrLen{#2}[\tmpnbcaract]%
+ \foreach \i in {1,...,\tmpnbcaract}{%
+ \StrChar{#2}{\i}[\tmpchar]%
+ %majuscule minuscule
+ \IfStrEq{\tmpchar}{ }%
+ {~}%
+ {%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchar}%
+ {%
+ \StrPosition{\aLPHaBeTMajusc}{\tmpchar}[\tmpcoeffx]%
+ }%
+ {%
+ \StrPosition{\aLPHaBeTminusc}{\tmpchar}[\tmpcoeffx]%
+ }%
+ \ifboolKV[chiffcesar]{Dechiffr}%
+ {\xdef\tmpcoeffx{\xintiirem{\xinteval{\tmpcoeffx-\tmpdecalcesar}}{26}}}%
+ {\xdef\tmpcoeffx{\xintiirem{\xinteval{\tmpcoeffx+\tmpdecalcesar}}{26}}}%
+ \IfSubStr{\aLPHaBeTMajusc}{\tmpchar}%
+ {%
+ \StrChar{\aLPHaBeTMajusc}{\tmpcoeffx}%
+ }%
+ {%
+ \StrChar{\aLPHaBeTminusc}{\tmpcoeffx}%
+ }%
+ }%
+ }%
+}
+
\endinput \ No newline at end of file
diff --git a/macros/latex/contrib/proflycee/tex/proflycee-tools-listings.tex b/macros/latex/contrib/proflycee/tex/proflycee-tools-listings.tex
index 5f094083fa..280970d88c 100644
--- a/macros/latex/contrib/proflycee/tex/proflycee-tools-listings.tex
+++ b/macros/latex/contrib/proflycee/tex/proflycee-tools-listings.tex
@@ -551,6 +551,22 @@
% }
%%------PRESENTATIONDECODES CLASSIQUES
+\tcbset{stylecodetex/.style={%
+ enhanced,boxrule=0.75pt,colframe=teal!50!black,%
+ sharp corners,top=1mm,bottom=1mm,left=1mm,right=1mm,middle=1mm,%
+ before skip=0.5\baselineskip,after skip=0.5\baselineskip,%
+ skin=bicolor,colback=teal!10,colbacklower=white,
+ fontupper=\footnotesize,fontlower=\footnotesize,%
+ listing engine=listings,%
+ %watermark text={\faCode},watermark opacity=0.25,watermark zoom=0.50,%
+ title={{\scriptsize\faCode} Code \LaTeX},
+ lefttitle=1mm,
+ fonttitle=\bfseries\footnotesize\sffamily,colbacktitle=teal!75!black
+ }
+}
+
+\NewTCBListing{PresCodeLaTeX}{ m }{stylecodetex,listing options={style=tcblatex,basicstyle=\footnotesize\ttfamily,keywordstyle=\bfseries\color{blue},tabsize=2},#1}
+
\NewTCBListing{PresentationCode}{ O{CouleurVertForet} m }{%
sharp corners=downhill,enhanced,arc=12pt,skin=bicolor,%
colback=#1!5!white,colframe=#1!75!black,colbacklower=white,%