Search in sources :

Example 1 with ClassicDataObject

use of org.jcryptool.core.operations.dataobject.classic.ClassicDataObject in project core by jcryptool.

the class AbstractAlgorithmHandler method addActionItem.

/**
 * Adds the cryptographic action information as a new <code>ActionItem</code> to the <b>Actions view</b>. Adding the
 * new ActionItem must be executed in an async way since a Job may be used to execute the cryptographic operation.
 *
 * @param algorithm The executed AbstractAlgorithm implementation
 */
private void addActionItem(AbstractAlgorithm algorithm) {
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    if ((Boolean) // $NON-NLS-1$
    service.getCommand("org.jcryptool.actions.recordCommand").getState("org.jcryptool.actions.recordCommand.toggleState").getValue()) {
        // $NON-NLS-1$
        final ActionItem item = new ActionItem(output.getName(), algorithm.getAlgorithmName());
        item.setPluginId(this.getId());
        if (algorithm instanceof AbstractClassicAlgorithm) {
            ClassicDataObject dataobject = (ClassicDataObject) dataObject;
            if (dataobject.getOpmode() == 0) {
                // $NON-NLS-1$
                item.setActionType("encrypt");
            } else if (dataobject.getOpmode() == 1) {
                // $NON-NLS-1$
                item.setActionType("decrypt");
            }
            item.setAlphabet(dataobject.getAlphabet().getName());
            dataobject.setFilterNonAlphaChars(((AbstractClassicAlgorithm) algorithm).isFilter());
            item.setParams(DataObjectConverter.propertiesToHashtable(dataobject));
            item.setDataObjectType(dataobject.getClass().getName());
        } else if (algorithm instanceof AbstractModernAlgorithm) {
            ModernDataObject dataobject = (ModernDataObject) dataObject;
            item.setParams(DataObjectConverter.propertiesToHashtable(dataobject));
            item.setDataObjectType(dataobject.getClass().getName());
        }
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                ActionCascadeService.getInstance().addItem(item);
            }
        });
    }
}
Also used : AbstractClassicAlgorithm(org.jcryptool.core.operations.algorithm.classic.AbstractClassicAlgorithm) AbstractModernAlgorithm(org.jcryptool.core.operations.algorithm.modern.AbstractModernAlgorithm) ActionItem(org.jcryptool.actions.core.types.ActionItem) ModernDataObject(org.jcryptool.core.operations.dataobject.modern.ModernDataObject) IModernDataObject(org.jcryptool.core.operations.dataobject.modern.IModernDataObject) ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject) IClassicDataObject(org.jcryptool.core.operations.dataobject.classic.IClassicDataObject) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 2 with ClassicDataObject

use of org.jcryptool.core.operations.dataobject.classic.ClassicDataObject in project core by jcryptool.

the class StartHandler method convert.

public IDataObject convert(ActionItem actionItem) {
    IDataObject dataobject = DataObjectConverter.hashtableToProperties(actionItem.getParams(), actionItem.getDataObjectType());
    if (dataobject instanceof ClassicDataObject) {
        AbstractAlphabet alphabet = AlphabetsManager.getInstance().getAlphabetByName(actionItem.getAlphabet());
        ((ClassicDataObject) dataobject).setAlphabet(alphabet);
        if ("encrypt".equals(actionItem.getActionType())) {
            // $NON-NLS-1$
            ((ClassicDataObject) dataobject).setOpmode(AbstractAlgorithm.ENCRYPT_MODE);
        } else if ("decrypt".equals(actionItem.getActionType())) {
            // $NON-NLS-1$
            ((ClassicDataObject) dataobject).setOpmode(AbstractAlgorithm.DECRYPT_MODE);
        }
    }
    return dataobject;
}
Also used : IDataObject(org.jcryptool.core.operations.dataobject.IDataObject) ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject) AbstractAlphabet(org.jcryptool.core.operations.alphabets.AbstractAlphabet)

Example 3 with ClassicDataObject

use of org.jcryptool.core.operations.dataobject.classic.ClassicDataObject in project core by jcryptool.

the class AbstractClassicAlgorithm method init.

/**
 * Initializes the Algorithm with its key parameters
 *
 * @param opmode encrypt or decrypt (mode)
 * @param input input text
 * @param alphabet filter alphabet
 * @param key the operation's key
 * @param key2 the second key
 * @param transformData the transformation data used to transform the text before the real operation, may be
 *            <code>null</code> in case no transformation should be applied
 */
public void init(int opmode, String input, AbstractAlphabet alphabet, char[] key, char[] key2, TransformData transformData) {
    this.dataObject = new ClassicDataObject();
    this.dataObject.setTransformData(transformData);
    this.dataObject.setPlain(filterTextByTransformData(input, transformData));
    this.dataObject.setAlphabet(alphabet);
    this.dataObject.setKey(key);
    this.dataObject.setOpmode(opmode);
    this.dataObject.setKey2(key2);
}
Also used : ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject)

Example 4 with ClassicDataObject

use of org.jcryptool.core.operations.dataobject.classic.ClassicDataObject in project core by jcryptool.

the class AbstractClassicAlgorithm method init.

/**
 * Initializes the Algorithm with its key parameters
 *
 * @param opmode encrypt or decrypt (mode)
 * @param input input text
 * @param alphabet filter alphabet
 * @param key the operation's key
 * @param nullchar the char (in some algorithms) that is the one to replace a missing character in the
 *            26-char-alphabet
 * @param transformData the transformation data used to transform the text before the real operation, may be
 *            <code>null</code> in case no transformation should be applied
 */
public void init(int opmode, InputStream input, AbstractAlphabet alphabet, char[] key, char nullchar, TransformData transformData) {
    this.dataObject = new ClassicDataObject();
    this.dataObject.setTransformData(transformData);
    try {
        this.dataObject.setInputStream(filterStreamByTransformData(input, transformData));
    } catch (Exception e) {
        LogUtil.logError(OperationsPlugin.PLUGIN_ID, e);
        this.dataObject.setInputStream(input);
    }
    this.dataObject.setAlphabet(alphabet);
    this.dataObject.setKey(key);
    this.dataObject.setOpmode(opmode);
    this.dataObject.setNullchar(nullchar);
}
Also used : ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with ClassicDataObject

use of org.jcryptool.core.operations.dataobject.classic.ClassicDataObject in project core by jcryptool.

the class AbstractClassicAlgorithm method init.

/**
 * Initializes the Algorithm with its key parameters
 *
 * @param opmode encrypt or decrypt (mode)
 * @param input input text
 * @param alphabet filter alphabet
 * @param key the operation's key
 * @param nullchar the char (in some algorithms) that is the one to replace a missing character in the
 *            26-char-alphabet
 * @param transformData the transformation data used to transform the text before the real operation, may be
 *            <code>null</code> in case no transformation should be applied
 */
public void init(int opmode, String input, AbstractAlphabet alphabet, char[] key, char nullchar, TransformData transformData) {
    this.dataObject = new ClassicDataObject();
    this.dataObject.setTransformData(transformData);
    this.dataObject.setPlain(filterTextByTransformData(input, transformData));
    this.dataObject.setAlphabet(alphabet);
    this.dataObject.setKey(key);
    this.dataObject.setOpmode(opmode);
    this.dataObject.setNullchar(nullchar);
}
Also used : ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject)

Aggregations

ClassicDataObject (org.jcryptool.core.operations.dataobject.classic.ClassicDataObject)6 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ICommandService (org.eclipse.ui.commands.ICommandService)1 ActionItem (org.jcryptool.actions.core.types.ActionItem)1 AbstractClassicAlgorithm (org.jcryptool.core.operations.algorithm.classic.AbstractClassicAlgorithm)1 AbstractModernAlgorithm (org.jcryptool.core.operations.algorithm.modern.AbstractModernAlgorithm)1 AbstractAlphabet (org.jcryptool.core.operations.alphabets.AbstractAlphabet)1 IDataObject (org.jcryptool.core.operations.dataobject.IDataObject)1 IClassicDataObject (org.jcryptool.core.operations.dataobject.classic.IClassicDataObject)1 IModernDataObject (org.jcryptool.core.operations.dataobject.modern.IModernDataObject)1 ModernDataObject (org.jcryptool.core.operations.dataobject.modern.ModernDataObject)1