Exemple #1
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();
  }