Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Snowleopard_wu
Java
提交
8426bedf
J
Java
项目概览
Snowleopard_wu
/
Java
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Java
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8426bedf
编写于
5月 10, 2020
作者:
Stepfen Shawn
提交者:
GitHub
5月 10, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1307 from SageTendo/Development
CaesarBruteForce
上级
4690efbe
2567859e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
0 deletion
+56
-0
src/main/java/com/ciphers/CaesarBruteForce.java
src/main/java/com/ciphers/CaesarBruteForce.java
+29
-0
src/test/java/com/ciphers/CaesarBruteForceTest.java
src/test/java/com/ciphers/CaesarBruteForceTest.java
+27
-0
未找到文件。
src/main/java/com/ciphers/CaesarBruteForce.java
0 → 100644
浏览文件 @
8426bedf
package
com.ciphers
;
public
class
CaesarBruteForce
{
/**
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
* @param message (String) The encrypted text.
* @param Key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
*/
public
String
decrypt
(
String
message
,
int
Key
)
{
final
String
LETTERS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
if
(
Key
>
26
){
System
.
out
.
println
();
return
null
;
}
StringBuilder
plainText
=
new
StringBuilder
();
for
(
char
character
:
message
.
toUpperCase
().
toCharArray
())
{
int
index
=
LETTERS
.
indexOf
(
character
);
if
(
index
!=
-
1
)
{
index
-=
Key
;
//Wrap around index value range[1-26]
if
(
index
<
0
)
{
index
+=
LETTERS
.
length
();
}
plainText
.
append
(
LETTERS
.
toCharArray
()[
index
]);
}
else
{
plainText
.
append
(
character
);
}
}
System
.
out
.
println
(
String
.
format
(
"Current Decryption Key %d : %s"
,
Key
,
plainText
));
return
plainText
.
append
(
decrypt
(
message
,
Key
+
1
)).
toString
();
}
}
src/test/java/com/ciphers/CaesarBruteForceTest.java
0 → 100644
浏览文件 @
8426bedf
package
com.ciphers
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
class
CaesarBruteForceTest
{
@Test
void
testCaesarBruteForce
()
{
CaesarBruteForce
cipher
=
new
CaesarBruteForce
();
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"TKFK"
,
1
).
contains
(
"JAVA"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"QHCH"
,
1
).
contains
(
"JAVA"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"LUHREIU"
,
1
).
contains
(
"VERBOSE"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"Mkockb"
,
1
).
contains
(
"CAESAR"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"olssv"
,
1
).
contains
(
"HELLO"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"Zvksxdohd"
,
1
).
contains
(
"PLAINTEXT"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"XGVKRIM"
,
1
).
contains
(
"ENCRYPT"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"OZRRVNQC123"
,
1
).
contains
(
"PASSWORD123"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"GEQDZMYQ"
,
1
).
contains
(
"USERNAME"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"IKHMXVMXW"
,
1
).
contains
(
"PROTECTED"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"ZPSRC-DMPACB"
,
1
).
contains
(
"BRUTE-FORCED"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"VCTKJ!"
,
1
).
contains
(
"PWNED!"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"JKLMNOP"
,
1
).
contains
(
"ABCDEFG"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"QFMDHCUFODVWQ"
,
1
).
contains
(
"CRYPTOGRAPHIC"
));
Assertions
.
assertSame
(
true
,
cipher
.
decrypt
(
"Dmbncdc"
,
1
).
contains
(
"ENCODED"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录