Esempio n. 1
0
 /**
  * Construction du Cryptotron
  *
  * @param src - source à crypter ou décrypter
  * @param mode - Crytpage ou Decryptage
  * @param cryptCentage
  * @param caeserKey
  */
 public Cryptotron(String src, CryptModeEnum mode, int cryptCentage, List<Integer> caeserKey) {
   this.src = src;
   this.mode = mode;
   this.centage = cryptCentage;
   this.centageBDecimal = new BigDecimal(this.centage);
   this.centageBDecimal = this.centageBDecimal.divide(BIGDEC_100, 2, RoundingMode.HALF_UP);
   this.keyList = caeserKey;
   this.split = CryptotronUtils.splitIntoWordsAndSpaces(this.src, this.mode);
 }
Esempio n. 2
0
  /**
   * Retourne la source traité par le {@link Cryptotron}
   *
   * @return
   */
  public String cypher() {
    if (this.centage == 0) return this.src;

    int nbWord = split.getWordIndexSet().size();

    TreeSet<Integer> cypheredIndex = new TreeSet<Integer>();
    // Selection des indexs mots à traiter

    Integer[] wordIndexArray = new Integer[split.getWordIndexSet().size()];
    split.getWordIndexSet().toArray(wordIndexArray);
    for (int i = 0; i < nbWord; i++) {
      if (i < split.getWordIndexSet().size() && isCyphered(cypheredIndex.size(), i))
        cypheredIndex.add(wordIndexArray[i]);
    }
    this.cypheredIndex = cypheredIndex;

    // sur tout les mots à crypter
    List<String> cryptedResult = new ArrayList<String>();
    for (int i = 0; i < split.getListOfWordsAndWhiteSpace().size(); i++) {
      String cypher = split.getListOfWordsAndWhiteSpace().get(i);
      if (!cypheredIndex.contains(new Integer(i)) || CryptotronUtils.isWhiteSpaceOnly(cypher)) {
        // Pas chiffré
        cypher = split.getListOfWordsAndWhiteSpace().get(i);
      } else {
        cypher = cryptIt(cypher, mode);
      }

      cryptedResult.add(cypher);
    }

    StringBuilder sb = new StringBuilder();
    for (String cypher : cryptedResult) {
      sb.append(cypher);
    }
    return sb.toString();
  }
Esempio n. 3
0
 /** @param mode the mode to set */
 public void setMode(CryptModeEnum mode) {
   this.mode = mode;
   this.split = CryptotronUtils.splitIntoWordsAndSpaces(this.src, this.mode);
 }
Esempio n. 4
0
 /** @param src the src to set */
 public void setSrc(String src) {
   this.src = src;
   this.split = CryptotronUtils.splitIntoWordsAndSpaces(this.src, this.mode);
 }