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.CipherInfoUtil; import com.mattrixwv.cipherstream.utils.CipherParameterUtil; import lombok.extern.slf4j.Slf4j; @Slf4j @RestController @RequestMapping("/cipherStream/baconian") public class BaconianCipherController{ @GetMapping public ObjectNode getCipherInfo(){ MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); log.info("Getting info for {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); return CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION); } @GetMapping("/encode") public ObjectNode encodeBaconian(@RequestBody ObjectNode cipherParams){ MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian"); log.info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); 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 {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); 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; } }