Initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.mattrixwv.cipherstream;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
public class CipherStreamAPI{
|
||||
public static void main(String[] args){
|
||||
SpringApplication.run(CipherStreamAPI.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mattrixwv.cipherstream.aspect;
|
||||
|
||||
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Configuration
|
||||
public class CipherStreamLoggingAspect{
|
||||
public static final String CIPHER_NAME_LOGGING = "cipher";
|
||||
|
||||
|
||||
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) || @annotation(org.springframework.web.bind.annotation.GetMapping) || @annotation(org.springframework.web.bind.annotation.PutMapping) || @annotation(org.springframework.web.bind.annotation.PostMapping) || @annotation(org.springframework.web.bind.annotation.DeleteMapping)")
|
||||
public void mappedFunction(){
|
||||
//Intentionally blank
|
||||
}
|
||||
|
||||
@Pointcut("execution(* com.mattrixwv.cipherstream.controller..*(..))")
|
||||
public void cipherMethod(){
|
||||
//Intentionally blank
|
||||
}
|
||||
|
||||
@AfterReturning(pointcut = "cipherMethod() && mappedFunction()", returning = "returnedJson")
|
||||
public void getCipherInfo(ObjectNode returnedJson){
|
||||
//Print a log
|
||||
log.info("CipherStream log {}", returnedJson);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mattrixwv.cipherstream.config;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FullFilter extends OncePerRequestFilter{
|
||||
@Override
|
||||
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws ServletException, IOException{
|
||||
//Get the requestId
|
||||
if(request.getHeader("X-Request-Id") != null){
|
||||
MDC.put("requestId", request.getHeader("X-Request-Id"));
|
||||
}
|
||||
|
||||
//Get IP address
|
||||
if(request.getHeader("X-Forwarded-For") != null){
|
||||
MDC.put("ip", request.getHeader("X-Forwarded-For").split(",")[0]);
|
||||
}
|
||||
|
||||
//Get all of the parameters in the request and print them in the log
|
||||
StringJoiner parameters = new StringJoiner(", ");
|
||||
request.getParameterMap().entrySet().forEach(entry -> {
|
||||
if(!entry.getKey().equals("_")){
|
||||
String key = entry.getKey();
|
||||
String value = "";
|
||||
if(entry.getValue().length > 1){
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for(String str : entry.getValue()){
|
||||
joiner.add(str);
|
||||
}
|
||||
value = joiner.toString();
|
||||
}
|
||||
else{
|
||||
value = entry.getValue()[0];
|
||||
}
|
||||
parameters.add(key + "->" + value);
|
||||
}
|
||||
});
|
||||
if(parameters.length() > 0){
|
||||
log.info("Request parameters: {}", parameters);
|
||||
}
|
||||
|
||||
//Get the path
|
||||
MDC.put("url", request.getRequestURI());
|
||||
|
||||
//Continue to the controller
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
//Clear the MDC for the next request
|
||||
MDC.clear();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mattrixwv.cipherstream.exception;
|
||||
|
||||
|
||||
public class InvalidCipherParameterException extends RuntimeException{
|
||||
public InvalidCipherParameterException(){
|
||||
super();
|
||||
}
|
||||
public InvalidCipherParameterException(String message){
|
||||
super(message);
|
||||
}
|
||||
public InvalidCipherParameterException(Throwable throwable){
|
||||
super(throwable);
|
||||
}
|
||||
public InvalidCipherParameterException(String message, Throwable throwable){
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.mattrixwv.cipherstream.utils;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class CipherParameterUtil{
|
||||
//Error messages
|
||||
public static final String PRESENT_MESSAGE = " must be present";
|
||||
public static final String INTEGER_MESSAGE = " must be an integer";
|
||||
public static final String TEXT_MESSAGE = " must be text";
|
||||
public static final String BOOLEAN_MESSAGE = " must be a boolean";
|
||||
public static final String INTEGER_ARRAY_MESSAGE = " must be an integer array";
|
||||
public static final String CHARACTER_MESSAGE = " must be a single character";
|
||||
//General
|
||||
public static final String PRESERVE_CAPITALS = "preserveCapitals";
|
||||
public static final String PRESERVE_WHITESPACE = "preserveWhitespace";
|
||||
public static final String PRESERVE_SYMBOLS = "preserveSymbols";
|
||||
public static final String INPUT_STRING = "inputString";
|
||||
public static final String OUTPUT_STRING = "outputString";
|
||||
public static final String KEYWORD = "keyword";
|
||||
|
||||
|
||||
//Caesar
|
||||
public static final String CAESAR_SHIFT_AMOUNT = "shiftAmount";
|
||||
|
||||
//Affine
|
||||
public static final String AFFINE_KEY_1 = "key1";
|
||||
public static final String AFFINE_KEY_2 = "key2";
|
||||
|
||||
//BaseX
|
||||
public static final String BASE_X_BASE = "base";
|
||||
|
||||
//ADFGX
|
||||
public static final String SQUARE_KEYWORD = "squareKeyword";
|
||||
|
||||
//Hill
|
||||
public static final String HILL_KEY = "key";
|
||||
|
||||
//Rail Fence
|
||||
public static final String RAIL_FENCE_RAILS = "rails";
|
||||
|
||||
//Trifid
|
||||
public static final String TRIFID_FILL = "fill";
|
||||
public static final String TRIFID_GROUP_LENGTH = "groupLength";
|
||||
|
||||
|
||||
public static void verifyUniversalParams(ObjectNode params){
|
||||
if(!params.has(PRESERVE_CAPITALS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_CAPITALS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(PRESERVE_WHITESPACE)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_WHITESPACE).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(PRESERVE_SYMBOLS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_SYMBOLS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyParamsWithKeyword(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(KEYWORD)){
|
||||
throw new InvalidCipherParameterException(KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(KEYWORD).isTextual()){
|
||||
throw new InvalidCipherParameterException(KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyCaesarParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(CAESAR_SHIFT_AMOUNT)){
|
||||
throw new InvalidCipherParameterException(CAESAR_SHIFT_AMOUNT + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(CAESAR_SHIFT_AMOUNT).isInt()){
|
||||
throw new InvalidCipherParameterException(CAESAR_SHIFT_AMOUNT + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyAffineParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(AFFINE_KEY_1)){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_1 + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(AFFINE_KEY_1).isInt()){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_1 + INTEGER_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(AFFINE_KEY_2)){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_2 + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(AFFINE_KEY_2).isInt()){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_2 + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyAtbashParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
}
|
||||
|
||||
public static void verifyBaconianParams(ObjectNode params){
|
||||
if(!params.has(PRESERVE_CAPITALS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_CAPITALS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyBaseXParams(ObjectNode params){
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(BASE_X_BASE)){
|
||||
throw new InvalidCipherParameterException(BASE_X_BASE + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(BASE_X_BASE).isInt()){
|
||||
throw new InvalidCipherParameterException(BASE_X_BASE + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifySquareKeyword(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(SQUARE_KEYWORD)){
|
||||
throw new InvalidCipherParameterException(SQUARE_KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(SQUARE_KEYWORD).isTextual()){
|
||||
throw new InvalidCipherParameterException(SQUARE_KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyHillParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(HILL_KEY)){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(HILL_KEY).isArray()){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + INTEGER_ARRAY_MESSAGE);
|
||||
}
|
||||
if(!params.get(HILL_KEY).get(0).isArray()){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + INTEGER_ARRAY_MESSAGE);
|
||||
}
|
||||
if(!params.get(HILL_KEY).get(0).get(0).isInt()){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + INTEGER_ARRAY_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyMorseParams(ObjectNode params){
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyPolybiusParams(ObjectNode params){
|
||||
if(!params.has(PRESERVE_WHITESPACE)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_WHITESPACE).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(PRESERVE_SYMBOLS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_SYMBOLS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(KEYWORD)){
|
||||
throw new InvalidCipherParameterException(KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(KEYWORD).isTextual()){
|
||||
throw new InvalidCipherParameterException(KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyRailFenceParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(RAIL_FENCE_RAILS)){
|
||||
throw new InvalidCipherParameterException(RAIL_FENCE_RAILS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(RAIL_FENCE_RAILS).isInt()){
|
||||
throw new InvalidCipherParameterException(RAIL_FENCE_RAILS + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyTrifidParams(ObjectNode params){
|
||||
verifyParamsWithKeyword(params);
|
||||
|
||||
if(!params.has(TRIFID_FILL)){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(TRIFID_FILL).isTextual()){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + TEXT_MESSAGE);
|
||||
}
|
||||
if(params.get(TRIFID_FILL).asText().length() > 1){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + CHARACTER_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(TRIFID_GROUP_LENGTH)){
|
||||
throw new InvalidCipherParameterException(TRIFID_GROUP_LENGTH);
|
||||
}
|
||||
if(!params.get(TRIFID_GROUP_LENGTH).isInt()){
|
||||
throw new InvalidCipherParameterException(TRIFID_GROUP_LENGTH + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user