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