Skip to content

Commit dfe189b

Browse files
authored
Resolve build errors & cleanup structure (TheAlgorithms#2334)
1 parent 3559002 commit dfe189b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+418
-1102
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
4+
title: ""
5+
labels: ""
6+
assignees: ""
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

1312
**To Reproduce**
1413
Steps to reproduce the behavior:
14+
1515
1. Go to '...'
1616
2. Click on '....'
1717
3. Scroll down to '....'

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
4+
title: ""
5+
labels: ""
6+
assignees: ""
87
---
98

109
**Is your feature request related to a problem? Please describe.**

.github/workflows/build.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
name: Build Project
2-
3-
on:
4-
pull_request:
5-
push:
6-
branches:
7-
- master
8-
1+
name: Build
2+
on: push
93
jobs:
104
build:
115
runs-on: ubuntu-latest
126
steps:
137
- uses: actions/checkout@v2
148
- uses: actions/setup-python@v2
15-
- name: Set up JDK 12
9+
- name: Set up JDK 17
1610
uses: actions/setup-java@v1
1711
with:
18-
java-version: 12
12+
java-version: 17
1913
- run: find . -type f -name "*.java" > sources.txt
2014
- run: javac @sources.txt

.github/workflows/checkstyle.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
name: Prettier
2-
3-
on:
4-
pull_request:
5-
push:
6-
branches:
7-
- master
8-
- Development
9-
1+
name: Prettify
2+
on: push
103
jobs:
114
prettier:
125
runs-on: ubuntu-latest
13-
146
steps:
157
- name: Checkout
168
uses: actions/checkout@v2
@@ -20,7 +12,7 @@ jobs:
2012
- name: Prettify code
2113
uses: creyD/prettier_action@v3.3
2214
with:
23-
prettier_options: --write **/*.{java}
24-
commit_message: 'style: prettify code'
15+
prettier_options: --write **/*.java
16+
commit_message: 'Prettify code'
2517
env:
2618
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/stale.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Close stale issues and PRs'
22
on:
33
schedule:
4-
- cron: '0 */10 * * *'
4+
- cron: '0 0 * * *'
55
jobs:
66
stale:
77
runs-on: ubuntu-latest
@@ -16,4 +16,3 @@ jobs:
1616
exempt-pr-labels: 'dont-close'
1717
days-before-stale: 30
1818
days-before-close: 7
19-
operations-per-run: 150
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push
2-
name: update_directory_md
3-
on: [push]
2+
name: Update Directory
3+
on: push
44
jobs:
55
update_directory_md:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@master
99
- uses: actions/setup-python@master
10-
- name: update_directory_md
10+
- name: Update Directory
1111
shell: python
1212
run: |
1313
import os
@@ -63,5 +63,5 @@ jobs:
6363
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
6464
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
6565
git add DIRECTORY.md
66-
git commit -am "updating DIRECTORY.md" || true
66+
git commit -am "Update directory" || true
6767
git push --force origin HEAD:$GITHUB_REF || true

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
:+1::tada: Before guiding you through the contribution process TheAlgorithms/Java thank you for being one of us! :+1::tada:
2-
31
## How to contribute?
42

53
#### **Did you find a bug?**

ciphers/AES.java renamed to Ciphers/AES.java

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ciphers;
1+
package Ciphers;
22

33
import java.math.BigInteger;
44
import java.util.Scanner;
@@ -215,58 +215,53 @@ public class AES {
215215

216216
/**
217217
* Subroutine of the Rijndael key expansion.
218-
*
219-
* @param t
220-
* @param rconCounter
221-
* @return
222218
*/
223219
public static BigInteger scheduleCore(BigInteger t, int rconCounter) {
224-
String rBytes = t.toString(16);
220+
StringBuilder rBytes = new StringBuilder(t.toString(16));
225221

226222
// Add zero padding
227223
while (rBytes.length() < 8) {
228-
rBytes = "0" + rBytes;
224+
rBytes.insert(0, "0");
229225
}
230226

231227
// rotate the first 16 bits to the back
232228
String rotatingBytes = rBytes.substring(0, 2);
233229
String fixedBytes = rBytes.substring(2);
234230

235-
rBytes = fixedBytes + rotatingBytes;
231+
rBytes = new StringBuilder(fixedBytes + rotatingBytes);
236232

237233
// apply S-Box to all 8-Bit Substrings
238234
for (int i = 0; i < 4; i++) {
239-
String currentByteBits = rBytes.substring(i * 2, (i + 1) * 2);
235+
StringBuilder currentByteBits = new StringBuilder(rBytes.substring(i * 2, (i + 1) * 2));
240236

241-
int currentByte = Integer.parseInt(currentByteBits, 16);
237+
int currentByte = Integer.parseInt(currentByteBits.toString(), 16);
242238
currentByte = SBOX[currentByte];
243239

244240
// add the current RCON value to the first byte
245241
if (i == 0) {
246242
currentByte = currentByte ^ RCON[rconCounter];
247243
}
248244

249-
currentByteBits = Integer.toHexString(currentByte);
245+
currentByteBits = new StringBuilder(Integer.toHexString(currentByte));
250246

251247
// Add zero padding
252248

253249
while (currentByteBits.length() < 2) {
254-
currentByteBits = '0' + currentByteBits;
250+
currentByteBits.insert(0, '0');
255251
}
256252

257253
// replace bytes in original string
258-
rBytes = rBytes.substring(0, i * 2) + currentByteBits + rBytes.substring((i + 1) * 2);
254+
rBytes = new StringBuilder(rBytes.substring(0, i * 2) + currentByteBits + rBytes.substring((i + 1) * 2));
259255
}
260256

261257
// t = new BigInteger(rBytes, 16);
262258
// return t;
263-
return new BigInteger(rBytes, 16);
259+
return new BigInteger(rBytes.toString(), 16);
264260
}
265261

266262
/**
267263
* Returns an array of 10 + 1 round keys that are calculated by using Rijndael key schedule
268264
*
269-
* @param initialKey
270265
* @return array of 10 + 1 round keys
271266
*/
272267
public static BigInteger[] keyExpansion(BigInteger initialKey) {
@@ -332,11 +327,11 @@ public static BigInteger[] keyExpansion(BigInteger initialKey) {
332327
public static int[] splitBlockIntoCells(BigInteger block) {
333328

334329
int[] cells = new int[16];
335-
String blockBits = block.toString(2);
330+
StringBuilder blockBits = new StringBuilder(block.toString(2));
336331

337332
// Append leading 0 for full "128-bit" string
338333
while (blockBits.length() < 128) {
339-
blockBits = '0' + blockBits;
334+
blockBits.insert(0, '0');
340335
}
341336

342337
// split 128 to 8 bit cells
@@ -356,24 +351,22 @@ public static int[] splitBlockIntoCells(BigInteger block) {
356351
*/
357352
public static BigInteger mergeCellsIntoBlock(int[] cells) {
358353

359-
String blockBits = "";
354+
StringBuilder blockBits = new StringBuilder();
360355
for (int i = 0; i < 16; i++) {
361-
String cellBits = Integer.toBinaryString(cells[i]);
356+
StringBuilder cellBits = new StringBuilder(Integer.toBinaryString(cells[i]));
362357

363358
// Append leading 0 for full "8-bit" strings
364359
while (cellBits.length() < 8) {
365-
cellBits = '0' + cellBits;
360+
cellBits.insert(0, '0');
366361
}
367362

368-
blockBits += cellBits;
363+
blockBits.append(cellBits);
369364
}
370365

371-
return new BigInteger(blockBits, 2);
366+
return new BigInteger(blockBits.toString(), 2);
372367
}
373368

374369
/**
375-
* @param ciphertext
376-
* @param key
377370
* @return ciphertext XOR key
378371
*/
379372
public static BigInteger addRoundKey(BigInteger ciphertext, BigInteger key) {
@@ -383,7 +376,6 @@ public static BigInteger addRoundKey(BigInteger ciphertext, BigInteger key) {
383376
/**
384377
* substitutes 8-Bit long substrings of the input using the S-Box and returns the result.
385378
*
386-
* @param ciphertext
387379
* @return subtraction Output
388380
*/
389381
public static BigInteger subBytes(BigInteger ciphertext) {
@@ -401,7 +393,6 @@ public static BigInteger subBytes(BigInteger ciphertext) {
401393
* substitutes 8-Bit long substrings of the input using the inverse S-Box for decryption and
402394
* returns the result.
403395
*
404-
* @param ciphertext
405396
* @return subtraction Output
406397
*/
407398
public static BigInteger subBytesDec(BigInteger ciphertext) {
@@ -417,8 +408,6 @@ public static BigInteger subBytesDec(BigInteger ciphertext) {
417408

418409
/**
419410
* Cell permutation step. Shifts cells within the rows of the input and returns the result.
420-
*
421-
* @param ciphertext
422411
*/
423412
public static BigInteger shiftRows(BigInteger ciphertext) {
424413
int[] cells = splitBlockIntoCells(ciphertext);
@@ -454,8 +443,6 @@ public static BigInteger shiftRows(BigInteger ciphertext) {
454443
/**
455444
* Cell permutation step for decryption . Shifts cells within the rows of the input and returns
456445
* the result.
457-
*
458-
* @param ciphertext
459446
*/
460447
public static BigInteger shiftRowsDec(BigInteger ciphertext) {
461448
int[] cells = splitBlockIntoCells(ciphertext);
@@ -490,8 +477,6 @@ public static BigInteger shiftRowsDec(BigInteger ciphertext) {
490477

491478
/**
492479
* Applies the Rijndael MixColumns to the input and returns the result.
493-
*
494-
* @param ciphertext
495480
*/
496481
public static BigInteger mixColumns(BigInteger ciphertext) {
497482

@@ -511,8 +496,6 @@ public static BigInteger mixColumns(BigInteger ciphertext) {
511496

512497
/**
513498
* Applies the inverse Rijndael MixColumns for decryption to the input and returns the result.
514-
*
515-
* @param ciphertext
516499
*/
517500
public static BigInteger mixColumnsDec(BigInteger ciphertext) {
518501

@@ -563,7 +546,6 @@ public static BigInteger encrypt(BigInteger plainText, BigInteger key) {
563546
* Decrypts the ciphertext with the key and returns the result
564547
*
565548
* @param cipherText The Encrypted text which we want to decrypt
566-
* @param key
567549
* @return decryptedText
568550
*/
569551
public static BigInteger decrypt(BigInteger cipherText, BigInteger key) {
@@ -596,30 +578,27 @@ public static void main(String[] args) {
596578
char choice = input.nextLine().charAt(0);
597579
String in;
598580
switch (choice) {
599-
case 'E':
600-
case 'e':
581+
case 'E', 'e' -> {
601582
System.out.println("Choose a plaintext block (128-Bit Integer in base 16):");
602583
in = input.nextLine();
603584
BigInteger plaintext = new BigInteger(in, 16);
604585
System.out.println("Choose a Key (128-Bit Integer in base 16):");
605586
in = input.nextLine();
606587
BigInteger encryptionKey = new BigInteger(in, 16);
607588
System.out.println(
608-
"The encrypted message is: \n" + encrypt(plaintext, encryptionKey).toString(16));
609-
break;
610-
case 'D':
611-
case 'd':
589+
"The encrypted message is: \n" + encrypt(plaintext, encryptionKey).toString(16));
590+
}
591+
case 'D', 'd' -> {
612592
System.out.println("Enter your ciphertext block (128-Bit Integer in base 16):");
613593
in = input.nextLine();
614594
BigInteger ciphertext = new BigInteger(in, 16);
615595
System.out.println("Choose a Key (128-Bit Integer in base 16):");
616596
in = input.nextLine();
617597
BigInteger decryptionKey = new BigInteger(in, 16);
618598
System.out.println(
619-
"The deciphered message is:\n" + decrypt(ciphertext, decryptionKey).toString(16));
620-
break;
621-
default:
622-
System.out.println("** End **");
599+
"The deciphered message is:\n" + decrypt(ciphertext, decryptionKey).toString(16));
600+
}
601+
default -> System.out.println("** End **");
623602
}
624603
}
625604
}

0 commit comments

Comments
 (0)