Initial commit

This commit is contained in:
2024-04-07 19:41:57 -04:00
parent 2b3212cb44
commit 8f0d1c64bd
95 changed files with 6787 additions and 45 deletions

View File

@@ -0,0 +1,69 @@
package com.mattrixwv.cipherstream.controller.combination;
import org.slf4j.MDC;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
import com.mattrixwv.cipherstream.combination.ADFGVX;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("adfgvx")
public class AdfgvxCipherController{
@GetMapping("/encode")
public ObjectNode encodeAdfgvx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGVX");
log.info("Encoding ADFGVX");
CipherParameterUtil.verifySquareKeyword(cipherParams);
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
ADFGVX adfgvx = new ADFGVX(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = adfgvx.encode(squareKeyword, keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeAdfgvx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGVX");
log.info("Decoding ADFGVX");
CipherParameterUtil.verifySquareKeyword(cipherParams);
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
ADFGVX adfgvx = new ADFGVX(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = adfgvx.decode(squareKeyword, keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}