Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2815d52
Решение задачи
robotdorog Oct 1, 2021
7a8bb66
Добавлен .idea в .gitignore
robotdorog Oct 3, 2021
8264e77
Согласно замечаниям убрал два дублирущих метод. Оставил методы writer…
robotdorog Oct 17, 2021
0cd1faf
Создано 2 класса. Первый для шифрования/дешифрования, второй для чтен…
robotdorog Oct 21, 2021
83517a4
Внесены изменения в методы классов Cryptor и FileHandler
robotdorog Nov 12, 2021
b989939
Убрал эксепшены из класса Cryptor
robotdorog Nov 13, 2021
c6863c3
Добавлены тесты на методы crypt и decrypt
robotdorog Nov 17, 2021
5b5367e
Добавлены тесты
robotdorog Nov 19, 2021
e149b54
Добавлены тесты
robotdorog Nov 19, 2021
e8a7aa0
Исправлены ошибки, которые были обнаружены после проведения тестов
robotdorog Nov 22, 2021
54cad78
создан новый класс CryptorV2 с использованием StringBuilder, необходи…
robotdorog Nov 25, 2021
c714810
создан новый класс CryptorV2 с использованием StringBuilder и класс F…
robotdorog Nov 26, 2021
6bebfcb
создан новы методы для тестирования классов со StringBuilder
robotdorog Nov 29, 2021
5ef33fd
Изменены тесты, сделан импорт для @test
robotdorog Nov 30, 2021
7ab3ae7
Разработка класса оценки времени
robotdorog Dec 8, 2021
2585b13
корректировка main
robotdorog Dec 13, 2021
786fb4d
корректировка 2 main
robotdorog Dec 13, 2021
11af72e
корректировка 3 main
robotdorog Dec 13, 2021
20302e2
корректировка 4 main. Указал корректные пути файлов для чтение и записи
robotdorog Dec 13, 2021
f29194e
Закомментровано шифрование/дешифрование с использованием String
robotdorog Dec 13, 2021
6595456
Откорректированы тесты
robotdorog Dec 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/out/
.idea
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Cryptor.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="junit:junit:4.12" level="project" />
<orderEntry type="module-library">
<library name="JUnit5.4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.4.2/junit-jupiter-5.4.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.4.2/junit-jupiter-api-5.4.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.4.2/junit-platform-commons-1.4.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.4.2/junit-jupiter-params-5.4.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.4.2/junit-jupiter-engine-5.4.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.4.2/junit-platform-engine-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
1 change: 1 addition & 0 deletions Projects
Submodule Projects added at 95dc91
4 changes: 4 additions & 0 deletions src/Crypt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public interface Crypt {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crypt - глагол если я не ошибаюсь, этот интерфейс у тебя описывает сервис. Поэтому здесь должно быть существительное - Cryptor

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переименовал на Cryptor

public String crypt(String strToCrypt);
public String decrypt(String strToDecrypt);
}
40 changes: 40 additions & 0 deletions src/Cryptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.IOException;

public class Cryptor implements Crypt {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это сервис и для него правильно - Cryptor. Только вот он же не просто шифровальщик а с некоторой изюминкой, надо отразить это в названии.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переименовал на CryptorWithTimeAssessment


CryptorViaString cryptorViaString;
CryptorViaStringBuilder cryptorViaStringBuilder;

public Cryptor(CryptorViaString cryptorViaString, CryptorViaStringBuilder cryptorViaStringBuilder) {
this.cryptorViaString = cryptorViaString;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не вижу чтобы ты его использовал и сравнивал время выполнения. Сейчас ты используешь только второй

this.cryptorViaStringBuilder = cryptorViaStringBuilder;

}

public String crypt(String strToCrypt) {
long m = System.currentTimeMillis();
// String cryptedStringViaString = cryptorViaString.crypt(strToCrypt);
String cryptedStringViaStringBuilder = cryptorViaStringBuilder.crypt(strToCrypt);
double timeResult = (double) (System.currentTimeMillis() - m);
System.out.println("Время выполнения шифрования с ипсользованием StringBuilder: " + timeResult);

return cryptedStringViaStringBuilder;
}

public String decrypt(String strToDecrypt) {
long t = System.currentTimeMillis();
// String cryptedStringViaString = cryptorViaString.decrypt(strToDecrypt);
String cryptedStringViaStringBuilder = cryptorViaStringBuilder.decrypt(strToDecrypt);
double timeResult = (double) (System.currentTimeMillis() - t);
System.out.println("Время выполнения шифрования с ипсользованием StringBuilder: " + timeResult);

return cryptedStringViaStringBuilder;

}


}




155 changes: 155 additions & 0 deletions src/CryptorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import org.junit.Assert;
import org.junit.Test;


public class CryptorTest {
CryptorViaString cryptorViaString = new CryptorViaString();
CryptorViaStringBuilder cryptorViaStringBuilder = new CryptorViaStringBuilder();
StringBuilder testStringBuilder = new StringBuilder();


@Test
public void cryptBasicTest() {
String testString = "A2a3b3z3tcz3";
String resultString = cryptorViaString.crypt("AAaaabbbzzztczzz");
Assert.assertEquals(testString, resultString);
}

@Test
public void decryptBasicTest() {
String testString = "AAaaabbbzzztczzz";
String resultString = cryptorViaString.decrypt("A2a3b3z3tcz3");
Assert.assertEquals(testString, resultString);
}

@Test
public void cryptOneCharTest() {
String testString = "a";
String resultString = cryptorViaString.crypt("a");
Assert.assertEquals(testString, resultString);
}

@Test
public void decryptOneCharTest() {
String testString = "a";
String resultString = cryptorViaString.decrypt("a");
Assert.assertEquals(testString, resultString);
}

@Test
public void cryptEmptyStrTest() {
String testString = "";
String resultString = cryptorViaString.crypt("");
Assert.assertEquals(testString, resultString);
}

@Test
public void decryptEmptyStrTest() {
String testString = "";
String resultString = cryptorViaString.decrypt("");
Assert.assertEquals(testString, resultString);
}

@Test
public void cryptOneRepeatTest() {
String testString = "a3";
String resultString = cryptorViaString.crypt("aaa");
Assert.assertEquals(testString, resultString);
}

@Test
public void decryptOneRepeatTest() {
String testString = "aaa";
String resultString = cryptorViaString.decrypt("a3");
Assert.assertEquals(testString, resultString);
}

@Test
public void cryptNoRepeatTest() {
String testString = "abcdef";
String resultString = cryptorViaString.crypt("abcdef");
Assert.assertEquals(testString, resultString);
}

@Test
public void decryptNoRepeatTest() {
String testString = "abcdef";
String resultString = cryptorViaString.decrypt("abcdef");
Assert.assertEquals(testString, resultString);

}

// CryptorViaStringBuilder

@Test
public void cryptBasicV2Test() {
String testStringBuilder = "A2a3b3z3tcz3";
String resultSringBuilder = cryptorViaStringBuilder.crypt("AAaaabbbzzztczzz");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void decryptBasicV2Test() {
String testStringBuilder = "AAaaabbbzzztczzz";
String resultSringBuilder = cryptorViaStringBuilder.decrypt("A2a3b3z3tcz3");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void cryptV2OneCharTest() {
String testStringBuilder = "a";
String resultSringBuilder = cryptorViaStringBuilder.crypt("a");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void decryptV2OneCharTest() {
String testStringBuilder = "a";
String resultSringBuilder = cryptorViaStringBuilder.decrypt("a");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void cryptV2EmptyStrTest() {
String testStringBuilder = "";
String resultSringBuilder = cryptorViaStringBuilder.crypt("");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void decryptV2EmptyStrTest() {
String testStringBuilder = "";
String resultSringBuilder = cryptorViaStringBuilder.decrypt("");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void cryptV2OneRepeatTest() {
String testStringBuilder = "a3";
String resultSringBuilder = cryptorViaStringBuilder.crypt("aaa");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void decryptV2OneRepeatTest() {
String testStringBuilder = "aaa";
String resultSringBuilder = cryptorViaStringBuilder.decrypt("a3");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void cryptV2NoRepeatTest() {
String testStringBuilder = "abcdef";
String resultSringBuilder = cryptorViaStringBuilder.crypt("abcdef");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}

@Test
public void decryptV2NoRepeatTest() {
String testStringBuilder = "abcdef";
String resultSringBuilder = cryptorViaStringBuilder.decrypt("abcdef");
Assert.assertEquals(testStringBuilder, resultSringBuilder);
}


}
66 changes: 66 additions & 0 deletions src/CryptorViaString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

public class CryptorViaString implements Crypt {

@Override
public String crypt(String strToCrypt) {

String result = "";

if (strToCrypt != null && !strToCrypt.equals("")) {
int count = 0;
char currentChar = 0;

for (int i = 0; i < strToCrypt.length(); i++) {
if (currentChar == strToCrypt.charAt(i)) {
count++;
} else {
if (currentChar != 0)
result += currentChar;

if (count > 1) {
result += count;
}
currentChar = strToCrypt.charAt(i);
count = 1;
}
}
if (count > 1) {
result += strToCrypt.charAt(strToCrypt.length() - 1);
result += count;
} else
result += strToCrypt.charAt(strToCrypt.length() - 1);
}
return result;
}

@Override
public String decrypt(String strToDecrypt) {

String result = "";
char currentChar = 0;
int count;

if (strToDecrypt != null && !strToDecrypt.equals("")) {

for (int i = 0; i < strToDecrypt.length(); i++) {
if (Character.isDigit(strToDecrypt.charAt(i))) {
count = Character.getNumericValue(strToDecrypt.charAt(i));
for (int j = 1; j < count; j++) {
result += currentChar;
}
} else {
currentChar = strToDecrypt.charAt(i);
if (currentChar != 0)
result += currentChar;
}
}

if (!Character.isDigit(strToDecrypt.charAt(strToDecrypt.length() - 1)) &&
!(currentChar == (strToDecrypt.charAt(strToDecrypt.length() - 1))))
result += currentChar;
}
return result;
}
}


Loading