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