diff --git a/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.html b/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.html index c2caca64..af93679c 100644 --- a/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.html +++ b/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.html @@ -3,7 +3,7 @@ Essais de chiffrement pour un framadate zéro knoledge
-

Chiffrement simple

+

1) Chiffrement simple

Les ordinateurs font des opérations très rapidement sur des nombres, pour coder et décoder des textes, il suffit donc de les convertir en nombre et faire des opérations plus ou moins complexes avec. @@ -32,6 +32,7 @@
+ On peut donc convertir notre texte en cette suite de nombres: @@ -39,7 +40,7 @@
-

Avec un peu de sel?

+

2) Avec un peu de sel?

({{ salt.length }} caractères)
@@ -50,7 +51,7 @@ {{ simpleCipheredTextWithSalt }} -

On hashe le sel

+

3) On hashe le sel

Pour gagner en aléatoire on peut passer le sel dans une fonction de hashage cryptographique, telle que @@ -78,7 +79,7 @@
-

Légèrement épicé

+

4) Légèrement épicé

simple chiffrement avec un sel avant et un saupoudrage du sel sur chacun des caractères de la phrase. la valeur du caractère est ajoutée à la valeur du caractère du sel correspondant. une fois arrivé à la fin du sel on reprend au début pour saupoudrer toute la phrase à chiffrer. Ce qui donne @@ -89,7 +90,7 @@
-

On en remet une couche

+

5) On en remet une couche

Les nombres que l'on a obtenu peuvent être transmis après une opération de conversion en caractères. On a donc autant de caractères que juste avant. ça ressemble déjà plus à un message pas évident à déchiffrer. Le nouveau texte fait {{ layerOnSpread.length }} caractères. @@ -124,20 +125,73 @@
+
+

Calcul d'entropie de Shannon

+ Un nombre élevé est signe de difficulté à deviner par calcul. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
score d'entropietexte à évaluer
{{ getEntropy(plainText).toFixed(3) }}{{ plainText }}
{{ getEntropy(simpleCipheredText).toFixed(3) }} +

{{ simpleCipheredText }}

+
{{ getEntropy(simpleCipheredTextWithSalt).toFixed(3) }} +

{{ simpleCipheredTextWithSalt }}

+
{{ getEntropy(simpleCipheredTextWithHashedSalt).toFixed(3) }} +

{{ simpleCipheredTextWithHashedSalt }}

+
{{ getEntropy(convertIntToText(simpleCipheredTextWithHashedSalt)).toFixed(3) }} +

{{ convertIntToText(simpleCipheredTextWithHashedSalt) }}

+
{{ getEntropy(simpleCipheredTextWithHashedSpreadSalt).toFixed(3) }} +

{{ simpleCipheredTextWithHashedSpreadSalt }}

+
{{ getEntropy(layerOnSpread).toFixed(3) }} +

{{ layerOnSpread }}

+
+

Chiffrement AES

- - texte avancé à déchiffrer -
- - salt - - initial_vector -
- - key + + + + + + + + + +
diff --git a/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.scss b/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.scss index 831df7ea..9ce5229a 100644 --- a/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.scss +++ b/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.scss @@ -25,3 +25,13 @@ .title { margin-top: 1em; } + +.entropy { + .limited-text { + max-width: 50% !important; + overflow: scroll; + text-overflow: ellipsis; + height: 2em; + display: block; + } +} diff --git a/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.ts b/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.ts index 4c801907..17a5cd0e 100644 --- a/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.ts +++ b/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.ts @@ -42,6 +42,9 @@ export class CipheringComponent implements OnInit { get simpleCipheredTextWithHashedSalt() { return this.convertTextToIntMixedSalt(this.md5(this.salt) + this.plainText); } + get simpleCipheredTextWithHashedSpreadSalt() { + return this.convertTextToIntMixedSalt(this.md5(this.salt) + this.plainText); + } get layerOnSpread() { return this.convertIntToText(this.simpleCipheredTextWithHashedSalt, false); } @@ -166,4 +169,22 @@ export class CipheringComponent implements OnInit { md5(someText) { return CipherLib.md5(someText); } + getEntropy(s) { + let sum = 0, + len = s.length; + this.process(s, (k, f) => { + const p = f / len; + sum -= (p * Math.log(p)) / Math.log(2); + }); + return sum; + } + process(s, evaluator) { + let h = Object.create(null), + k; + s.split('').forEach((c) => { + (h[c] && h[c]++) || (h[c] = 1); + }); + if (evaluator) for (k in h) evaluator(k, h[k]); + return h; + } }