Skip to content
Snippets Groups Projects
Commit 992ed687 authored by 20041679 .'s avatar 20041679 .
Browse files

bruteforce

parents
No related branches found
No related tags found
No related merge requests found
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<component name="libraryTable">
<library name="byteLib">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../byteLib.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/../byteLib.jar!/doc" />
</JAVADOC>
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/BruteForce.iml" filepath="$PROJECT_DIR$/BruteForce.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?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="byteLib" level="project" />
</component>
</module>
\ No newline at end of file
F
\ No newline at end of file
.(?
\ No newline at end of file
import it.uniupo.byteLib.BitStringGenerator;
import it.uniupo.byteLib.NonPrintableCharactersException;
import it.uniupo.byteLib.Tools;
import java.util.Arrays;
public class BruteForce {
public static void main(String[] args) throws NonPrintableCharactersException {
{
System.out.println("OTP-3");
var c = Tools.readByteFlow("OTP-3");
bruteforce(c, 3);
}
{
System.out.println("keystr-1x3");
var c = Tools.readByteFlow("keystr-1x3");
bruteforce(c, 1);
}
}
private static void bruteforce(byte[] c, int n) throws NonPrintableCharactersException {
var bsGen = new BitStringGenerator(n);
bsGen.zeroInit();
while (!bsGen.isMax()) {
var repetition = bsGen.nextVal();
var key = Arrays.copyOf(repetition, n);
for (int i = repetition.length - 1; i < n; i++) {
key[i] = repetition[i % repetition.length];
}
var attempt = Xor.xorCipher(c, key);
if (Tools.isUText(attempt)) {
System.out.println(Tools.bytesToString(attempt));
}
}
}
}
public class Xor {
public static byte[] xorCipher(byte[] c, byte[] k) {
byte[] ret = c.clone();
for (int i = 0; i < c.length; ++i) {
ret[i] ^= k[i % k.length];
}
return ret;
}
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment