Cypher

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 3110aa204dff3bbc8fe1fc29d3b9660ccc54b337
parent e7f7f61376cfd44a591712dfe7dd100a896c32df
Author: Minerva-Juppiter <ryouturn@gmail.com>
Date:   Tue, 27 Sep 2022 22:10:52 +0900


Diffstat:
A22U22_0308_プログラム一式.zip | 0
MCypherChecker.cs | 60++++++++++++++++++++++++++++++------------------------------
MEncrypt.cs | 22+++++++++++-----------
MKey.cs | 21++++++++++++---------
MQuestion.cs | 2+-
MResdFiles.cs | 10+++++-----
MSortProgram.cs | 43++++++++++++++++++++++++++-----------------
Mtest.cs | 2+-
8 files changed, 86 insertions(+), 74 deletions(-)

diff --git a/22U22_0308_プログラム一式.zip b/22U22_0308_プログラム一式.zip Binary files differ. diff --git a/CypherChecker.cs b/CypherChecker.cs @@ -38,7 +38,7 @@ namespace Cypher //復号プログラム //変数宣言 - double[] order = new double[100]; + double[] order = new double[1000]; int inNumber = 0; SHA512 shaM = new SHA512Managed(); //インスタンス @@ -93,17 +93,17 @@ namespace Cypher int amari; bool multipleJudgment; //データサイズに適した数ずつ引っこ抜く - if (howLongDateInt % 100 == 0) + if (howLongDateInt % 1000 == 0) { - quotient = howLongDateInt / 100; - amari = howLongDateInt % 100; + quotient = howLongDateInt / 1000; + amari = howLongDateInt % 1000; multipleJudgment = true; } else { - //100で割り切れない場合は、99で割って、その余りをすべてamariにぶち込む - quotient = howLongDateInt / 99; - amari = howLongDateInt - quotient * 99; + //1000で割り切れない場合は、999で割って、その余りをすべてamariにぶち込む + quotient = howLongDateInt / 999; + amari = howLongDateInt - quotient * 999; multipleJudgment = false; } @@ -130,8 +130,8 @@ namespace Cypher int outNumber = 0; if (multipleJudgment) { - //100で割り切れないとき - while (arreyNumber < 100) + //1000で割り切れないとき + while (arreyNumber < 1000) { //参照すべき番号を検索 indexNumber = Array.IndexOf(order, arreyNumber); @@ -153,11 +153,11 @@ namespace Cypher } else { - //100で割り切れない数の場合 + //1000で割り切れない数の場合 //余りの位置を特定 - int whereAmari = Array.IndexOf(order, 99); + int whereAmari = Array.IndexOf(order, 999); - while (arreyNumber < 100) + while (arreyNumber < 1000) { indexNumber = Array.IndexOf(order, arreyNumber); //inNumber 80 //indexNumberとamariの関係で場合分け @@ -190,10 +190,10 @@ namespace Cypher //データを元の長さに整理 - //ファイルサイズが100以下の場合 - if (howLongDateInt < 100) + //ファイルサイズが1000以下の場合 + if (howLongDateInt < 1000) { - Array.Copy(sorded, 0, dates, 0, 100 - howLongDateInt); + Array.Copy(sorded, 0, dates, 0, 1000 - howLongDateInt); } else { @@ -221,7 +221,7 @@ namespace Cypher //復号プログラム //変数宣言 - double[] order = new double[100]; + double[] order = new double[1000]; int inNumber = 0; SHA512 shaM = new SHA512Managed(); //インスタンス @@ -276,17 +276,17 @@ namespace Cypher int amari; bool multipleJudgment; //データサイズに適した数ずつ引っこ抜く - if (howLongDateInt % 100 == 0) + if (howLongDateInt % 1000 == 0) { - quotient = howLongDateInt / 100; - amari = howLongDateInt % 100; + quotient = howLongDateInt / 1000; + amari = howLongDateInt % 1000; multipleJudgment = true; } else { - //100で割り切れない場合は、99で割って、その余りをすべてamariにぶち込む - quotient = howLongDateInt / 99; - amari = howLongDateInt - quotient * 99; + //1000で割り切れない場合は、999で割って、その余りをすべてamariにぶち込む + quotient = howLongDateInt / 999; + amari = howLongDateInt - quotient * 999; multipleJudgment = false; } @@ -308,8 +308,8 @@ namespace Cypher int outNumber = 0; if (multipleJudgment) { - //100で割り切れないとき - while (arreyNumber < 100) + //1000で割り切れないとき + while (arreyNumber < 1000) { //参照すべき番号を検索 indexNumber = Array.IndexOf(order, arreyNumber); @@ -331,11 +331,11 @@ namespace Cypher } else { - //100で割り切れない数の場合 + //1000で割り切れない数の場合 //余りの位置を特定 - int whereAmari = Array.IndexOf(order, 99); + int whereAmari = Array.IndexOf(order, 999); - while (arreyNumber < 100) + while (arreyNumber < 1000) { indexNumber = Array.IndexOf(order, arreyNumber); //inNumber 80 //indexNumberとamariの関係で場合分け @@ -368,10 +368,10 @@ namespace Cypher //データを元の長さに整理 - //ファイルサイズが100以下の場合 - if (howLongDateInt < 100) + //ファイルサイズが1000以下の場合 + if (howLongDateInt < 1000) { - Array.Copy(sorded, 0, dates, 0, 100 - howLongDateInt); + Array.Copy(sorded, 0, dates, 0, 1000 - howLongDateInt); } else { diff --git a/Encrypt.cs b/Encrypt.cs @@ -14,8 +14,8 @@ namespace Cypher //暗号化 //変数宣言 - int[] order = new int[100]; - string[] date = new string[100]; + int[] order = new int[1000]; + string[] date = new string[1000]; int quotient; //商 int amari = 0; //あまり int inNumber = 0; //入力データ番号 @@ -84,11 +84,11 @@ namespace Cypher int indexStart; int outNumber = 0; inNumber = 0; - if (bs.Length % 100 == 0) + if (bs.Length % 1000 == 0) { - quotient = bs.Length / 100; + quotient = bs.Length / 1000; //百で割り切れる場合 - while (arrayNumber < 100) + while (arrayNumber < 1000) { indexNumuber = order[arrayNumber]; indexStart = quotient * indexNumuber; @@ -106,19 +106,19 @@ namespace Cypher else { //割り切れない場合 - quotient = bs.Length / 99; - amari = bs.Length - quotient * 99; - int where99 = Array.IndexOf(order, 99); + quotient = bs.Length / 999; + amari = bs.Length - quotient * 999; + int where999 = Array.IndexOf(order, 999); - while (arrayNumber < 100) + while (arrayNumber < 1000) { indexNumuber = Array.IndexOf(order, arrayNumber); - if (indexNumuber < where99) + if (indexNumuber < where999) { indexStart = quotient * indexNumuber; indexEnd = quotient * (indexNumuber + 1); } - else if (indexNumuber == where99) + else if (indexNumuber == where999) { indexStart = indexNumuber * quotient; indexEnd = indexNumuber * quotient + amari; diff --git a/Key.cs b/Key.cs @@ -10,22 +10,25 @@ namespace Cypher { public void createKey() { - double[] ints = new double[100]; - for(int i = 0; i < 100; i++) + int count; + double[] ints = new double[1000]; + for(int i = 0; i < 1000; i++) { ints[i] = i; } - double[] order = new double[100]; + double[] order = new double[1000]; order = GeneratKey(); Console.WriteLine("Now genarating key..."); //相関係数が0.5より小さくなるまで鍵ファイルを生成し続ける。 - while (ComputeCoeff(order.ToArray(), ints.ToArray()) < 0.3) + count = 0; + while (ComputeCoeff(order.ToArray(), ints.ToArray()) > 0.9) { order = GeneratKey(); + count++; + Console.WriteLine(count); } - int count = 1; Question question = new Question(); string whereKeyFile = question.Questions("Where will you want to create the keyFile?", false); @@ -45,12 +48,12 @@ namespace Cypher //順序ファイルの生成 int random; int count = 1; - double[] order = new double[100]; - //百個数字が埋められるまで繰り返す。 - while (count < 100) + double[] order = new double[1000]; + //1000個数字が埋められるまで繰り返す。 + while (count < 1000) { var randomer = new Random(); - random = randomer.Next(minValue: 0, maxValue: 100); + random = randomer.Next(minValue: 0, maxValue: 1000); //今までにない数かどうかを評価 if (Array.IndexOf(order, random) < 0) diff --git a/Question.cs b/Question.cs @@ -14,7 +14,7 @@ namespace Cypher string answer = Console.ReadLine(); if (exsis) { - while (answer == null | File.Exists(answer) == false) + while (answer != null && File.Exists(answer) == false) { Console.WriteLine("You have not typed anything or you are specifying a file that does not exist"); answer = Console.ReadLine(); diff --git a/ResdFiles.cs b/ResdFiles.cs @@ -10,22 +10,22 @@ namespace Cypher { public int[] ReadKeyFile(string whereKeyFile) { - int[] order = new int[100]; + int[] order = new int[1000]; int inNumber = 0; - //keyファイルが100行か確認する + //keyファイルが1000行か確認する string[] lines = File.ReadAllLines(whereKeyFile); - if (lines.Length != 100) + if (lines.Length != 1000) { Console.WriteLine("The key file you selected is not key file"); Console.WriteLine("We can't continu this program!"); Console.WriteLine("We will stop by 10seconds."); - Thread.Sleep(1000); + Thread.Sleep(10000); Environment.Exit(0); } //順序ファイルの読み込み StreamReader sr = new StreamReader(whereKeyFile); //配列に順序を読み込み - while (inNumber < 100) + while (inNumber < 1000) { order[inNumber] = int.Parse(sr.ReadLine()); inNumber++; diff --git a/SortProgram.cs b/SortProgram.cs @@ -14,7 +14,7 @@ namespace Cypher //復号プログラム //変数宣言 - int[] order = new int[100]; + int[] order = new int[1000]; int inNumber = 0; SHA512 shaM = new SHA512Managed(); //インスタンス @@ -63,24 +63,33 @@ namespace Cypher } //byteのデータを長さの数だけ用意 - byte[] dates = new byte[howLongDateInt]; - byte[] sorded = new byte[howLongDateInt]; + int lenghtOfDate; + if (howLongDateInt < 1000) + { + lenghtOfDate = 1000; + } + else + { + lenghtOfDate = howLongDateInt; + } + byte[] dates = new byte[lenghtOfDate]; + byte[] sorded = new byte[lenghtOfDate]; int quotient; int amari; bool multipleJudgment; //データサイズに適した数ずつ引っこ抜く - if (howLongDateInt % 100 == 0) + if (howLongDateInt % 1000 == 0) { - quotient = howLongDateInt / 100; - amari = howLongDateInt % 100; + quotient = howLongDateInt / 1000; + amari = howLongDateInt % 1000; multipleJudgment = true; } else { - //100で割り切れない場合は、99で割って、その余りをすべてamariにぶち込む - quotient = howLongDateInt / 99; - amari = howLongDateInt - quotient * 99; + //1000で割り切れない場合は、999で割って、その余りをすべてamariにぶち込む + quotient = howLongDateInt / 999; + amari = howLongDateInt - quotient * 999; multipleJudgment = false; } @@ -128,8 +137,8 @@ namespace Cypher int outNumber = 0; if (multipleJudgment) { - //100で割り切れないとき - while (arreyNumber < 100) + //1000で割り切れないとき + while (arreyNumber < 1000) { //参照すべき番号を検索 indexNumber = Array.IndexOf(order, arreyNumber); @@ -151,11 +160,11 @@ namespace Cypher } else { - //100で割り切れない数の場合 + //1000で割り切れない数の場合 //余りの位置を特定 - int whereAmari = Array.IndexOf(order, 99); + int whereAmari = Array.IndexOf(order, 999); - while (arreyNumber < 100) + while (arreyNumber < 1000) { indexNumber = Array.IndexOf(order, arreyNumber); //inNumber 80 //indexNumberとamariの関係で場合分け @@ -189,10 +198,10 @@ namespace Cypher //データを元の長さに整理 - //ファイルサイズが100以下の場合 - if (howLongDateInt < 100) + //ファイルサイズが1000未満の場合 + if (howLongDateInt < 1000) { - Array.Copy(sorded, 0, dates, 0, 100 - howLongDateInt); + Array.Copy(sorded, 0, dates, 0, 1000 - howLongDateInt); } else { diff --git a/test.cs b/test.cs @@ -28,7 +28,7 @@ namespace Cypher { Question question = new Question(); string whereCreateDateFile = question.Questions("where do you want to create test date file?", false); - int[] date = new int[100]; + int[] date = new int[1000]; for (int i = 0; i < date.Length; i++) { date[i] = i;