From 8c3b2444ed491afe327a2397db23b7d028dbbadb Mon Sep 17 00:00:00 2001 From: Yasmidrog Date: Mon, 7 Jan 2019 21:39:18 +0300 Subject: [PATCH 1/5] Create paircipher.js --- www/assets/js/paircipher.js | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 www/assets/js/paircipher.js diff --git a/www/assets/js/paircipher.js b/www/assets/js/paircipher.js new file mode 100644 index 0000000..3bb50bb --- /dev/null +++ b/www/assets/js/paircipher.js @@ -0,0 +1,41 @@ +let alpha="АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; +String.prototype.replaceAt=function(index, replacement) { + return this.substr(0, index) + replacement+ this.substr(index + replacement.length); +}; +function paircipher(key, phrase){ + + if(key.length>16) + return null; + key=key.toUpperCase().trim(); + phrase = phrase.toUpperCase().replace("Ё","Е"); + let newAlpha=alpha+''; + for(let i=0;i-1){ + phrase=phrase.replaceAt(i,newAlpha.charAt(pos)+''); + } + } + return phrase; +} +$(document).ready(function (e) { + document.getElementById("process").disabled = true; + $("#key").keyup(function (e) { + + e.target.value=e.target.value.replace(/[^а-яё]/ig,''); + if(e.target.value.length>16) + e.target.value=e.target.value.substr(0, 16); + e.target.value=Array.from(new Set(e.target.value)).join(''); + $("#counter").html(e.target.value.length+"/16") + if(e.target.value.length==16) + document.getElementById("process").disabled = false; + else document.getElementById("process").disabled = true; + + }) + $("#process").click(function () { + $("#result").val(paircipher($("#key").val(), $("#phrase").val())) + }) +}); From cd4ade23c43c3257f7acc2114489774b4eeb53c6 Mon Sep 17 00:00:00 2001 From: Yasmidrog Date: Mon, 7 Jan 2019 21:39:51 +0300 Subject: [PATCH 2/5] Add files via upload --- www/paircipher.html | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 www/paircipher.html diff --git a/www/paircipher.html b/www/paircipher.html new file mode 100644 index 0000000..2c7b87e --- /dev/null +++ b/www/paircipher.html @@ -0,0 +1,35 @@ + + + + + Кдинозначный парный шифр + + + + + +
+ +
+
+ +
+
+ +
+ + + \ No newline at end of file From 229e9a238a4e0c0baf6eb61c9dd0d83c4c311c9a Mon Sep 17 00:00:00 2001 From: Yasmidrog Date: Mon, 7 Jan 2019 22:29:30 +0300 Subject: [PATCH 3/5] Update paircipher.html --- www/paircipher.html | 105 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/www/paircipher.html b/www/paircipher.html index 2c7b87e..84c327f 100644 --- a/www/paircipher.html +++ b/www/paircipher.html @@ -2,34 +2,93 @@ - Кдинозначный парный шифр + Единозначный парный шифр - + + -
- -
-
- -
-
- -
- + + + + + +
+
+
+

Единозначный парный шифр

+
+ + + +
+
+

Единозначный парный шифр- шифр подстановки, в котором половина букв алфавита связана с другой половиной

+

+
+ +
+ +
+
+

Как это выглядит?

+ + + +
+
+ +
+
+

Происхождение

+

Использовался революционерами Российской Имеприи. является ненадежным, поэтому использовался только для коротких записок

+

+
+
+ +
+ +

Шифратор/Дешифратор (при нынешнем алфавите в шифре исполюзуются 16 букв без Ё)

+ +
+
+ +
+ 0/16 +
+
+
+

Текст для шифрования:

+ +
+
+ +
+
+

Зашифрованный текст

+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+ + + +
+ - \ No newline at end of file + From e15f885202bd7bbb1742172db4f9c5c80793f834 Mon Sep 17 00:00:00 2001 From: Yasmidrog Date: Mon, 7 Jan 2019 22:30:06 +0300 Subject: [PATCH 4/5] Update paircipher.js --- www/assets/js/paircipher.js | 75 ++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/www/assets/js/paircipher.js b/www/assets/js/paircipher.js index 3bb50bb..411b0d2 100644 --- a/www/assets/js/paircipher.js +++ b/www/assets/js/paircipher.js @@ -1,41 +1,62 @@ -let alpha="АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; -String.prototype.replaceAt=function(index, replacement) { - return this.substr(0, index) + replacement+ this.substr(index + replacement.length); +let alpha = "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; +String.prototype.replaceAt = function (index, replacement) { + return this.substr(0, index) + replacement + this.substr(index + replacement.length); }; -function paircipher(key, phrase){ - if(key.length>16) +function crypt(key, phrase) { + + if (key.length > 16) return null; - key=key.toUpperCase().trim(); - phrase = phrase.toUpperCase().replace("Ё","Е"); - let newAlpha=alpha+''; - for(let i=0;i-1){ - phrase=phrase.replaceAt(i,newAlpha.charAt(pos)+''); + key = key.toUpperCase().trim(); + phrase = phrase.toUpperCase().replace("Ё", "Е"); + let newAlpha = alpha + ''; + for (let i = 0; i < key.length; i++) + newAlpha = newAlpha.replace(key.charAt(i) + '', ''); + + console.log("cr: "+ key + "\n" + newAlpha); + for (let i = 0; i < phrase.length; i++) { + let pos = key.indexOf(phrase.charAt(i) + ''); + if (pos > -1) { + phrase = phrase.replaceAt(i, newAlpha.charAt(pos) + ''); + }else{ + let pos = newAlpha.indexOf(phrase.charAt(i) + ''); + if(pos>-1) + phrase = phrase.replaceAt(i, key.charAt(pos) + ''); } } return phrase; } + + $(document).ready(function (e) { - document.getElementById("process").disabled = true; + + document.getElementById("decrypt").disabled = true; + document.getElementById("crypt").disabled = true; + $("#key").keyup(function (e) { + e.target.value = e.target.value.replace(/[^а-яё]/ig, ''); + if (e.target.value.length > 16) + e.target.value = e.target.value.substr(0, 16); + e.target.value = Array.from(new Set(e.target.value)).join(''); + $("#counter").html(e.target.value.length + "/16") + if (e.target.value.length == 16) { + document.getElementById("crypt").disabled = false; + document.getElementById("decrypt").disabled = false; + + } + else { + document.getElementById("crypt").disabled = true; + document.getElementById("decrypt").disabled = true; + + } + + }) - e.target.value=e.target.value.replace(/[^а-яё]/ig,''); - if(e.target.value.length>16) - e.target.value=e.target.value.substr(0, 16); - e.target.value=Array.from(new Set(e.target.value)).join(''); - $("#counter").html(e.target.value.length+"/16") - if(e.target.value.length==16) - document.getElementById("process").disabled = false; - else document.getElementById("process").disabled = true; + $("#crypt").click(function () { + $("#result").val(crypt($("#key").val(), $("#phrase").val())) }) - $("#process").click(function () { - $("#result").val(paircipher($("#key").val(), $("#phrase").val())) + $("#decrypt").click(function () { + $("#phrase").val(crypt($("#key").val(), $("#result").val())) }) }); From f5713730cb8486890413510d4c61d6bc120b62d7 Mon Sep 17 00:00:00 2001 From: Yasmidrog Date: Mon, 7 Jan 2019 22:38:04 +0300 Subject: [PATCH 5/5] Update paircipher.html --- www/paircipher.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/paircipher.html b/www/paircipher.html index 84c327f..7f5923f 100644 --- a/www/paircipher.html +++ b/www/paircipher.html @@ -8,7 +8,7 @@ integrity="sha256-fNXJFIlca05BIO2Y5zh1xrShK3ME+/lYZ0j+ChxX2DA=" crossorigin="anonymous"> - +