Add a fictional cipher from "supergirl"

This commit is contained in:
zontreck 2024-07-27 02:27:08 -07:00
parent 1525640d19
commit c789219481
6 changed files with 105 additions and 2 deletions

1
Jenkinsfile vendored
View file

@ -40,6 +40,7 @@ pipeline {
post {
always {
archiveArtifacts artifacts: "*.tgz", fingerprint: true
archiveArtifacts artifacts: "out/*.bin", fingerprint: true
deleteDir()
}
}

31
bin/dbikc.dart Normal file
View file

@ -0,0 +1,31 @@
import 'dart:io';
import 'package:libac_dart/argparse/Args.dart';
import 'package:libac_dart/argparse/Builder.dart';
import 'package:libac_dart/argparse/CLIHelper.dart';
import 'package:libac_dart/argparse/types/Bool.dart';
import 'package:libac_dart/argparse/types/String.dart';
import 'package:libac_dart/utils/DBIKC.dart';
Future<int> main(List<String> args) async {
Arguments defaults = ArgumentsBuilder.builder()
.withArgument(StringArgument(
name: "value", value: "", description: "Text to encode/decode"))
.withArgument(BoolArgument(name: "help", description: "This help text"))
.build();
var helpText = CLIHelper.makeArgCLIHelp(defaults);
var HEADER = "Double Breasted Interrupted Key Cipher\nVersion: 1.0\n\n";
Arguments parsed = await CLIHelper.parseArgs(args, Arguments());
if (parsed.hasArg("help") || !parsed.hasArg("value")) {
print("${HEADER}${helpText}");
exit(0);
return 0;
} else {
print(DoubleBreastedInterruptedKeyCipher.encode(
parsed.getArg("value")!.getValue()));
}
return 0;
}

View file

@ -6,4 +6,5 @@ mkdir out
rm -rf out/*
flutter pub publish -f --skip-validation
dart compile exe -o out/server_test bin/server_test.dart
dart compile exe -o out/client_test bin/client_test.dart
dart compile exe -o out/client_test bin/client_test.dart
dart compile exe -o out/dbikc.bin bin/dbikc.dart

61
lib/utils/DBIKC.dart Normal file
View file

@ -0,0 +1,61 @@
class DoubleBreastedInterruptedKeyCipher {
static String encode(String text) {
// Define the vowel and consonant lists
List<String> vowels = ['A', 'E', 'I', 'O', 'U'];
List<String> consonants = [
'B',
'C',
'D',
'F',
'G',
'H',
'J',
'K',
'L',
'M',
'N',
'P',
'Q',
'R',
'S',
'T',
'V',
'W',
'X',
'Y',
'Z'
];
// Create a map for easy lookups
Map<String, String> vowelMap = {};
Map<String, String> consonantMap = {};
// Fill the maps by mirroring the lists
for (int i = 0; i < vowels.length; i++) {
vowelMap[vowels[i]] = vowels[vowels.length - 1 - i];
}
for (int i = 0; i < consonants.length; i++) {
consonantMap[consonants[i]] = consonants[consonants.length - 1 - i];
}
// Encode the text
StringBuffer encoded = StringBuffer();
for (int i = 0; i < text.length; i++) {
String char = text[i].toUpperCase();
if (vowelMap.containsKey(char)) {
encoded.write(vowelMap[char]);
} else if (consonantMap.containsKey(char)) {
encoded.write(consonantMap[char]);
} else {
encoded.write(char); // Keep non-alphabet characters unchanged
}
}
return encoded.toString();
}
static String decode(String text) {
// The decoding process is the same as encoding for this cipher
return encode(text);
}
}

View file

@ -1,6 +1,6 @@
name: libac_dart
description: "Aria's Creations code library"
version: 1.2.072224+1906
version: 1.2.072724+0210
homepage: "https://zontreck.com"

9
test/ciphers.dart Normal file
View file

@ -0,0 +1,9 @@
import 'package:libac_dart/utils/DBIKC.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';
void main() {
test("DBIKC", () {
expect("KAZNIA", DoubleBreastedInterruptedKeyCipher.encode("RUBNIU"));
});
}