Initial commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user