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 5dd96ba7..7489eef5 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
@@ -1,13 +1,13 @@
-
+
Essais de chiffrement pour un framadate zéro knoledge
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 fbf02e7f..5c92667c 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
@@ -1,6 +1,7 @@
.boxed-shadow {
padding: 1em;
margin-bottom: 1em;
+ width: 85%;
}
.cipher-result {
@@ -12,7 +13,14 @@
display: block;
min-width: 10ch;
min-height: 2em;
- max-width: 100%;
- overflow: hidden;
+ max-width: 50%;
+ overflow-x: scroll;
line-height: 2em;
+ app-copy-text {
+ float: left;
+ }
+}
+
+.title {
+ margin-top: 1em;
}
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 3c443ae1..930fe5ae 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
@@ -1,22 +1,22 @@
import { Component, OnInit } from '@angular/core';
// eslint-disable-next-line @typescript-eslint/no-var-requires
-import * as Crypto from 'crypto';
// documentation:
// https://medium.com/@spatocode/symmetric-encryption-in-javascript-bcb5fd14c273
// https://nodejs.org/api/crypto.html
+// https://preview.npmjs.com/package/ecma-nacl
@Component({
selector: 'app-ciphering',
templateUrl: './ciphering.component.html',
styleUrls: ['./ciphering.component.scss'],
})
export class CipheringComponent implements OnInit {
- // public plainText = 'le texte à chiffrer, coucou !';
- public plainText = 'salut les pipole';
+ public plainText = 'le texte à chiffrer, coucou !';
+ // public plainText = '1234';
public cipheredText =
'121-127-42-110-127-42-122-121-115-128-124-111-125-107-118-127-126-42-118-111-125-42-122-115-122-121-118-111';
algorithm = 'aes-192-cbc';
- public salt = 'ou du poivre';
+ public salt = 'ou du poivre heh';
public initial_vector = '';
public key;
public otherCipheredText = 'le texte à chiffrer, coucou !';
@@ -31,16 +31,29 @@ export class CipheringComponent implements OnInit {
get simpleCipheredText() {
return this.convertTextToInt(this.plainText);
}
+
get simpleCipheredTextWithSalt() {
return this.convertTextToInt(this.salt + this.plainText);
}
+ get simpleCipheredTextWithSpreadSalt() {
+ return this.convertTextToIntMixedSalt(this.salt + this.plainText);
+ }
+ get layerOnSpread() {
+ return this.convertIntToText(this.simpleCipheredTextWithSpreadSalt, false);
+ }
+
// ---------------------- make readable ----------------------
get simpleDeCipheredText() {
return this.convertIntToText(this.cipheredText);
}
+
get simpleDeCipheredTextWithSalt() {
return this.convertIntToText(this.salt + this.cipheredText);
}
+ get simpleDeCipheredTextWithSpreadSalt() {
+ return this.convertIntToTextMixedSalt(this.salt + this.cipheredText);
+ }
+
// ---------------------- conversions ----------------------
encrypt(someText) {
// this.key = Crypto.scryptSync(someText, 'salt', 24);
@@ -86,13 +99,62 @@ export class CipheringComponent implements OnInit {
}
return result;
}
- convertIntToText(value) {
+
+ convertIntToText(value, removeBeginning = true) {
let result = '';
const array = value.split('-');
for (let i = 0; i < array.length; i++) {
result += String.fromCharCode(array[i] - 10);
}
+ console.info('value, result', value, result);
+ // remove salt characters
+ if (removeBeginning) {
+ result = result.slice(this.salt.length, -1);
+ }
+ return result;
+ }
+
+ convertTextToIntMixedSalt(value) {
+ let result = '';
+ let saltIndex = 0;
+ for (let i = 0; i < value.length; i++) {
+ if (i < value.length - 1) {
+ result += value.charCodeAt(i) + 10 + this.salt.charCodeAt(saltIndex);
+ result += '-';
+ } else {
+ result += value.charCodeAt(i) + 10 + this.salt.charCodeAt(saltIndex);
+ }
+ saltIndex++;
+ if (saltIndex >= this.salt.length) {
+ saltIndex = 0;
+ }
+ }
+ return result;
+ }
+
+ convertIntToTextMixedSalt(value) {
+ let result = '';
+ const array = value.split('-');
+ let saltIndex = -1;
+
+ for (let i = 0; i < array.length; i++) {
+ // console.log(
+ // 'encodage',
+ // i,
+ // value.charCodeAt(i),
+ // saltIndex,
+ // this.salt.charCodeAt(saltIndex),
+ // value.charCodeAt(i) + 10 + this.salt.charCodeAt(saltIndex)
+ // );
+
+ result += String.fromCharCode(array[i] - 10 - this.salt.charCodeAt(saltIndex));
+ if (saltIndex > this.salt.length) {
+ saltIndex = 0;
+ } else {
+ saltIndex++;
+ }
+ }
// remove salt characters
return result.slice(this.salt.length);
}