use of org.jcryptool.core.operations.alphabets.AbstractAlphabet 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;
}
use of org.jcryptool.core.operations.alphabets.AbstractAlphabet in project core by jcryptool.
the class TransformData method fromString.
/**
* parses a Transformdata object from a String that was created using TransformData.toString();
*
* @return a TransformData instance
*/
public static TransformData fromString(String data) {
TransformData result = new TransformData();
try {
String[] split = data.split(SEPARATOR);
for (int i = 0; i < split.length; i++) {
if (split[i].contains(UPPERLOWERCASE_LABEL)) {
result.setUppercaseTransformationOn(true);
// $NON-NLS-1$
String value = split[i].substring(split[i].indexOf("=") + 1);
result.setDoUppercase(true);
if (value.equals("lowercase")) {
// $NON-NLS-1$
result.setDoUppercase(false);
}
}
if (split[i].contains(ALPHABET_LABEL)) {
result.setAlphabetTransformationON(true);
// $NON-NLS-1$
String value = split[i].substring(split[i].indexOf("=") + 1);
value = value.replaceAll(Pattern.quote(SEPARATOR_REPLACEMENT), SEPARATOR);
AbstractAlphabet alpha;
if (isAlphaStringStoreReference(value)) {
alpha = alphaStoreReferenceStringToAlpha(value);
} else {
alpha = stringToAlpha(value);
}
result.setSelectedAlphabet(alpha);
}
if (split[i].contains(BLANKS_LABEL)) {
result.setLeerTransformationON(true);
}
if (split[i].contains(UMLAUTS_LABEL)) {
result.setUmlautTransformationON(true);
}
}
} catch (Exception e) {
// $NON-NLS-1$
LogUtil.logError(OperationsPlugin.PLUGIN_ID, "Error when parsing TransformData from String");
}
return result;
}
use of org.jcryptool.core.operations.alphabets.AbstractAlphabet in project core by jcryptool.
the class TransformData method alphaStoreReferenceStringToAlpha.
/**
* Returns an alphabet from the store which is referenced in a string by "STORE_ALPHABET_STARTMARKER:[name]"
*
* @param value the reference string
* @return null if not found in the store, else the store alphabet
*/
private static AbstractAlphabet alphaStoreReferenceStringToAlpha(String value) {
String name = value.substring(STORE_ALPHABET_STARTMARKER.length());
AbstractAlphabet alpha = AlphabetsManager.getInstance().getAlphabetByName(name);
if (alpha == null) {
LogUtil.logWarning(OperationsPlugin.PLUGIN_ID, // $NON-NLS-1$ //$NON-NLS-2$
"could not load alphabet by name " + name + " for transformData. Using the default transformation instead.");
return AlphabetsManager.getInstance().getDefaultAlphabet();
}
return alpha;
}
Aggregations