/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.vutbr.feec.utko.fojtoval.krypto.sifry;

/**
 * Sifrovani a desifrovani pomoci transpozicni sifry.
 * @author fojtoval
 */
public class JednoduchaTranspozice extends Sifra{

    private String klic = null;

    /**
     * Sifrovani pomoci jednoduche transpozice.
     * @param zdroj otevreny text
     * @return sifrovany text
     */
    @Override
    public String sifruj(String zdroj) {
        return Utils.zmenaTextuTrans (zdroj, this.klic, true);
    }

    /**
     * Nastaveni a kontrola parametru sifry.
     * @param parametr
     */
    @Override
    public void setParametr(Object parametr) {
        
        if (parametr == null) {
            throw (new NullPointerException ("Parametr je null!"));
        } else if (!(parametr instanceof String)) {
                   throw (new IllegalArgumentException ("Parametr neni String! (" + parametr + ")"));
               }

          String key = (String)parametr;

          if (key.length() < 1 || key.length() > 20) {
              throw (new IllegalArgumentException ("Rozsah klice je 1-20 znaku. Bylo zadano " + klic.length() + "."));
		  }

          if (!key.matches ("^[a-z]+$")) {
              throw (new IllegalArgumentException ("Klic obsahuje nepovolene znaky."));
          }

          this.klic = key;

    }

    /**
     * Desifrovani jednoduche transpozice.
     * @param zdroj zasifrovany text
     * @return otevreny text
     */
    @Override
    public String lusti(String zdroj) {
        return Utils.zmenaTextuTransLus (zdroj, this.klic, true);
    }

    /**
     * Prevod desifrovaci abecedy na String.
     * @return nova abeceda
     */
    @Override
    public String abecedaLusToString() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Prevod sifrovaci abecedy na String.
     * @return nova abeceda
     */
    @Override
    public String abecedaSifToString() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
