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,52 @@
package com.mattrixwv.cipherstream.controller;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestControllerAdvice(annotations = RestController.class)
public class ExceptionRestController extends ResponseEntityExceptionHandler{
private static final ObjectMapper mapper = new ObjectMapper();
@ExceptionHandler(InvalidCipherParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ObjectNode invalidCipherParameterHandler(InvalidCipherParameterException error){
log.warn("Invalid user input was supplied: {}", error.getMessage());
ObjectNode returnJson = mapper.createObjectNode();
returnJson.put("message", error.getMessage());
return returnJson;
}
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ObjectNode genericExceptionHandler(Exception error){
log.error(error.getMessage(), error);
ObjectNode returnJson = mapper.createObjectNode();
returnJson.put("message", error.getMessage());
return returnJson;
}
}

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;
}
}

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.ADFGX;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("adfgx")
public class AdfgxCipherController{
@GetMapping("/encode")
public ObjectNode encodeAdfgx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGX");
log.info("Encoding ADFGX");
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();
ADFGX adfgx = new ADFGX(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = adfgx.encode(squareKeyword, keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeAdfgx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGX");
log.info("Decoding ADFGX");
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();
ADFGX adfgx = new ADFGX(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = adfgx.decode(squareKeyword, keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,69 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Affine;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/affine")
public class AffineCipherController{
@GetMapping("/encode")
public ObjectNode encodeAffine(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Affine");
log.info("Encoding Affine");
CipherParameterUtil.verifyAffineParams(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();
int key1 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_1).asInt();
int key2 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_2).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Affine affine = new Affine(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = affine.encode(key1, key2, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeAffine(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Affine");
log.info("Decoding Affine");
CipherParameterUtil.verifyAffineParams(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();
int key1 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_1).asInt();
int key2 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_2).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Affine affine = new Affine(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = affine.decode(key1, key2, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,65 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Atbash;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/atbash")
public class AtbashCipherController{
@GetMapping("/encode")
public ObjectNode encodeAtbash(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Atbash");
log.info("Encoding Atbash");
CipherParameterUtil.verifyAtbashParams(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Atbash atbash = new Atbash(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = atbash.encode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeAtbash(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Atbash");
log.info("Decoding Atbash");
CipherParameterUtil.verifyAtbashParams(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Atbash atbash = new Atbash(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = atbash.decode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Autokey;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/autokey")
public class AutokeyCipherController{
@GetMapping("/encode")
public ObjectNode encodeAutokey(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Autokey");
log.info("Encoding Autokey");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Autokey autokey = new Autokey(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = autokey.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeAutokey(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Autokey");
log.info("Decoding Autokey");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Autokey autokey = new Autokey(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = autokey.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,61 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Baconian;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/baconian")
public class BaconianCipherController{
@GetMapping("/encode")
public ObjectNode encodeBaconian(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian");
log.info("Encoding Baconian");
CipherParameterUtil.verifyBaconianParams(cipherParams);
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Baconian baconian = new Baconian(preserveCapitals);
String outputString = baconian.encode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeBaconian(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian");
log.info("Decoding Baconian");
CipherParameterUtil.verifyBaconianParams(cipherParams);
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Baconian baconian = new Baconian(preserveCapitals);
String outputString = baconian.decode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,61 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.BaseX;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/basex")
public class BaseXCipherController{
@GetMapping("/encode")
public ObjectNode encodeBaseX(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "BaseX");
log.info("Encoding BaseX");
CipherParameterUtil.verifyBaseXParams(cipherParams);
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
int base = cipherParams.get(CipherParameterUtil.BASE_X_BASE).asInt();
BaseX baseX = new BaseX(base);
String outputString = baseX.encode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeBaseX(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "BaseX");
log.info("Decoding BaseX");
CipherParameterUtil.verifyBaseXParams(cipherParams);
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
int base = cipherParams.get(CipherParameterUtil.BASE_X_BASE).asInt();
BaseX baseX = new BaseX(base);
String outputString = baseX.decode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Beaufort;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/beaufort")
public class BeaufortCipherController{
@GetMapping("/encode")
public ObjectNode encodeBeaufort(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Beaufort");
log.info("Encoding Beaufort");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Beaufort beaufort = new Beaufort(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = beaufort.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeBeaufort(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Beaufort");
log.info("Decoding Beaufort");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Beaufort beaufort = new Beaufort(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = beaufort.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,66 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Caesar;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/caesar")
public class CaesarCipherController{
@GetMapping("/encode")
public ObjectNode encodeCaesar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Caesar");
log.info("Encoding Caesar");
CipherParameterUtil.verifyCaesarParams(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();
int shiftAmount = cipherParams.get(CipherParameterUtil.CAESAR_SHIFT_AMOUNT).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Caesar caesar = new Caesar(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = caesar.encode(shiftAmount, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeCaesar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Caesar");
log.info("Decoding Caesar");
CipherParameterUtil.verifyCaesarParams(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();
int shiftAmount = cipherParams.get(CipherParameterUtil.CAESAR_SHIFT_AMOUNT).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Caesar caesar = new Caesar(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = caesar.decode(shiftAmount, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.OneTimePad;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/oneTimePad")
public class OneTimePadCipherController{
@GetMapping("/encode")
public ObjectNode encodeOneTimePad(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "One-Time Pad");
log.info("Encoding One Time Pad");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
OneTimePad oneTimePad = new OneTimePad(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = oneTimePad.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeOneTimePad(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "One-Time Pad");
log.info("Decoding One Time Pad");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
OneTimePad oneTimePad = new OneTimePad(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = oneTimePad.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Porta;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/porta")
public class PortaCipherController{
@GetMapping("/encode")
public ObjectNode encodePorta(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Porta");
log.info("Encoding Porta");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Porta porta = new Porta(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = porta.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodePorta(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Porta");
log.info("Decoding Porta");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Porta porta = new Porta(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = porta.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Substitution;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/substitution")
public class SubstitutionCipherController{
@GetMapping("/encode")
public ObjectNode encodeSubstitution(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Substitution");
log.info("Encoding Substitution");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Substitution substitution = new Substitution(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = substitution.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeSubstitution(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Substitution");
log.info("Decoding Substitution");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Substitution substitution = new Substitution(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = substitution.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.monosubstitution;
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.monosubstitution.Vigenere;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/vigenere")
public class VigenereCipherController{
@GetMapping("/encode")
public ObjectNode encodeVigenere(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Vigenere");
log.info("Encoding Vigenere");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Vigenere vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = vigenere.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeVigenere(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Vigenere");
log.info("Decoding Vigenere");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Vigenere vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = vigenere.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.Bifid;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/bifid")
public class BifidCipherController{
@GetMapping("/encode")
public ObjectNode encodeBifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Bifid");
log.info("Encoding Bifid");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Bifid bifid = new Bifid(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = bifid.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeBifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Bifid");
log.info("Decoding Bifid");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Bifid bifid = new Bifid(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = bifid.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.Columnar;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/columnar")
public class ColumnarCipherController{
@GetMapping("/encode")
public ObjectNode encodeColumnar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Columnar");
log.info("Encoding Columnar");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Columnar columnar = new Columnar(preserveCapitals, preserveWhitespace, preserveSymbols, true);
String outputString = columnar.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeColumnar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Columnar");
log.info("Decoding Columnar");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Columnar columnar = new Columnar(preserveCapitals, preserveWhitespace, preserveSymbols, true);
String outputString = columnar.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,69 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
import com.mattrixwv.cipherstream.polysubstitution.Hill;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/hill")
public class HillCipherController{
@GetMapping("/encode")
public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Hill");
log.info("Encoding Hill");
CipherParameterUtil.verifyHillParams(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();
int[][] key = new ObjectMapper().treeToValue(cipherParams.get(CipherParameterUtil.HILL_KEY), int[][].class);
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Hill hill = new Hill(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = hill.encode(key, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Hill");
log.info("Decoding Hill");
CipherParameterUtil.verifyHillParams(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();
int[][] key = new ObjectMapper().treeToValue(cipherParams.get(CipherParameterUtil.HILL_KEY), int[][].class);
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Hill hill = new Hill(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = hill.decode(key, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,59 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.Morse;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/morse")
public class MorseCodeController{
@GetMapping("/encode")
public ObjectNode encodeMorse(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Morse");
log.info("Encoding Morse");
CipherParameterUtil.verifyMorseParams(cipherParams);
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Morse morse = new Morse();
String outputString = morse.encode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeMorse(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Morse");
log.info("Decoding Morse");
CipherParameterUtil.verifyMorseParams(cipherParams);
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Morse morse = new Morse();
String outputString = morse.decode(inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.Playfair;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/playfair")
public class PlayfairCipherController{
@GetMapping("/encode")
public ObjectNode encodePlayfair(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Playfair");
log.info("Encoding Playfair");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Playfair playfair = new Playfair(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = playfair.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodePlayfair(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Playfair");
log.info("Decoding Playfair");
CipherParameterUtil.verifyParamsWithKeyword(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 inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Playfair playfair = new Playfair(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = playfair.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,65 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.PolybiusSquare;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/polybius")
public class PolybiusSquareController{
@GetMapping("/encode")
public ObjectNode encodePolybius(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Polybius Square");
log.info("Encoding Polybius");
CipherParameterUtil.verifyPolybiusParams(cipherParams);
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
PolybiusSquare polybiusSquare = new PolybiusSquare(preserveWhitespace, preserveSymbols);
String outputString = polybiusSquare.encode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodePolybius(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Polybius Square");
log.info("Decoding Polybius");
CipherParameterUtil.verifyPolybiusParams(cipherParams);
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
PolybiusSquare polybiusSquare = new PolybiusSquare(preserveWhitespace, preserveSymbols);
String outputString = polybiusSquare.decode(keyword, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,67 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.RailFence;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/railFence")
public class RailFenceController{
@GetMapping("/encode")
public ObjectNode encodeRailFence(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Rail Fence");
log.info("Encoding Rail Fence");
CipherParameterUtil.verifyRailFenceParams(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();
int rails = cipherParams.get(CipherParameterUtil.RAIL_FENCE_RAILS).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
RailFence railFence = new RailFence(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = railFence.encode(rails, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeRailFence(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Rail Fence");
log.info("Decoding Rail Fence");
CipherParameterUtil.verifyRailFenceParams(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();
int rails = cipherParams.get(CipherParameterUtil.RAIL_FENCE_RAILS).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
RailFence railFence = new RailFence(preserveCapitals, preserveWhitespace, preserveSymbols);
String outputString = railFence.decode(rails, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}

View File

@@ -0,0 +1,71 @@
package com.mattrixwv.cipherstream.controller.polysubstitution;
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.polysubstitution.Trifid;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/cipherStream/trifid")
public class TrifidCipherController{
@GetMapping("/encode")
public ObjectNode encodeTrifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Trifid");
log.info("Encoding Trifid");
CipherParameterUtil.verifyTrifidParams(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();
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asText().charAt(0);
int groupLength = cipherParams.get(CipherParameterUtil.TRIFID_GROUP_LENGTH).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Trifid trifid = new Trifid(preserveCapitals, preserveWhitespace, preserveSymbols, fill);
String outputString = trifid.encode(keyword, groupLength, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
@GetMapping("/decode")
public ObjectNode decodeTrifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Trifid");
log.info("Decoding Trifid");
CipherParameterUtil.verifyTrifidParams(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();
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asText().charAt(0);
int groupLength = cipherParams.get(CipherParameterUtil.TRIFID_GROUP_LENGTH).asInt();
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
Trifid trifid = new Trifid(preserveCapitals, preserveWhitespace, preserveSymbols, fill);
String outputString = trifid.decode(keyword, groupLength, inputString);
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
return cipherParams;
}
}