try { // Create the cipher Cipher blowCipher = Cipher.getInstance("Blowfish"); //$NON-NLS-1$ // Initialize the cipher for encryption blowCipher.init(Cipher.ENCRYPT_MODE, KEY); // Our cleartext as bytes byte[] cleartext = new String(source).getBytes("UTF-8"); //$NON-NLS-1$ // Encrypt the cleartext byte[] ciphertext = blowCipher.doFinal(cleartext); // Return a String representation of the cipher text return Base64.encode(ByteBuffer.wrap(ciphertext)).toString(); } catch (InvalidKeyException e) { LOG.severe(e.toString()); } catch (NoSuchAlgorithmException e) { LOG.severe(e.toString()); } catch (NoSuchPaddingException e) { LOG.severe(e.toString()); } catch (UnsupportedEncodingException e) { LOG.severe(e.toString()); } catch (IllegalStateException e) { LOG.severe(e.toString()); } catch (IllegalBlockSizeException e) { LOG.severe(e.toString()); } catch (BadPaddingException e) { LOG.severe(e.toString()); } return new String();
try { // Create the cipher Cipher blowCipher = Cipher.getInstance("Blowfish"); //$NON-NLS-1$ // Initialize the cipher for encryption blowCipher.init(Cipher.DECRYPT_MODE, KEY); // Encrypt the cleartext ByteBuffer ciphertext = Base64.decode(source); byte[] cipherArray = new byte[ciphertext.limit()]; ciphertext.get(cipherArray); // Our cleartext as bytes byte[] cleartext = blowCipher.doFinal(cipherArray); // Return a String representation of the cipher text return new String(cleartext, "UTF-8").toCharArray(); //$NON-NLS-1$ } catch (InvalidKeyException e) { LOG.severe(e.toString()); } catch (NoSuchAlgorithmException e) { LOG.severe(e.toString()); } catch (NoSuchPaddingException e) { LOG.severe(e.toString()); } catch (UnsupportedEncodingException e) { LOG.severe(e.toString()); } catch (IllegalStateException e) { LOG.severe(e.toString()); } catch (IllegalBlockSizeException e) { LOG.severe(e.toString()); } catch (BadPaddingException e) { LOG.severe(e.toString()); }
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/core/src/main/java/org/columba/core/base/Blowfish.java File path: /columba-1.4-src/core/src/main/java/org/columba/core/base/Blowfish.java
Method name: String encrypt(char[]) Method name: char[] decrypt(String)
Number of AST nodes: 7 Number of AST nodes: 8
1
try {
1
try {
2
	    // Create the cipher
2
	    // Create the cipher
3
	    Cipher blowCipher = Cipher.getInstance("Blowfish"); //$NON-NLS-1$
3
	    Cipher blowCipher = Cipher.getInstance("Blowfish"); //$NON-NLS-1$
4
	    // Initialize the cipher for encryption
4
	    // Initialize the cipher for encryption
5
	    blowCipher.init(Cipher.ENCRYPT_MODE, KEY);
5
	    blowCipher.init(Cipher.DECRYPT_MODE, KEY);
6
	    // Our cleartext as bytes
6
	    // Encrypt the cleartext
7
	    ByteBuffer ciphertext = Base64.decode(source);
7
	    byte[] cleartext = new String(source).getBytes("UTF-8"); //$NON-NLS-1$
8
	    byte[] c
8
	    // Encrypt the
9
ipherArray = new byte[ciphertext.limit()];
10
	    ciphertext.get(cipherArray);
9
 cleartext
11
	    // Our cleartext as bytes
10
	    byte[] ciphertext = blowCipher.doFinal(cleartext);
12
	    byte[] cleartext = blowCipher.doFinal(cipherArray);
11
	    // Return a String representation of the cipher text
13
	    // Return a String representation of the cipher text
12
	    return Base64.encode(ByteBuffer.wrap(ciphertext)).toString();
14
	    return new String(cleartext, "UTF-8").toCharArray(); //$NON-NLS-1$
13
	} catch (InvalidKeyException e) {
15
	} catch (InvalidKeyException e) {
14
	    LOG.severe(e.toString());
16
	    LOG.severe(e.toString());
15
	} catch (NoSuchAlgorithmException e) {
17
	} catch (NoSuchAlgorithmException e) {
16
	    LOG.severe(e.toString());
18
	    LOG.severe(e.toString());
17
	} catch (NoSuchPaddingException e) {
19
	} catch (NoSuchPaddingException e) {
18
	    LOG.severe(e.toString());
20
	    LOG.severe(e.toString());
19
	} catch (UnsupportedEncodingException e) {
21
	} catch (UnsupportedEncodingException e) {
20
	    LOG.severe(e.toString());
22
	    LOG.severe(e.toString());
21
	} catch (IllegalStateException e) {
23
	} catch (IllegalStateException e) {
22
	    LOG.severe(e.toString());
24
	    LOG.severe(e.toString());
23
	} catch (IllegalBlockSizeException e) {
25
	} catch (IllegalBlockSizeException e) {
24
	    LOG.severe(e.toString());
26
	    LOG.severe(e.toString());
25
	} catch (BadPaddingException e) {
27
	} catch (BadPaddingException e) {
26
	    LOG.severe(e.toString());
28
	    LOG.severe(e.toString());
27
	}
29
	}
28
	return new String();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.7
Clones locationClones are declared in the same class
Number of node comparisons48
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)2.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    try
    1
    try
    2
    Cipher blowCipher = Cipher.getInstance("Blowfish");
    2
    Cipher blowCipher = Cipher.getInstance("Blowfish");
    3
    blowCipher.init(Cipher.ENCRYPT_MODE, KEY);
    3
    blowCipher.init(Cipher.ENCRYPT_MODE, KEY);
    3
    blowCipher.init(Cipher.DECRYPT_MODE, KEY);
    Differences
    Expression1Expression2Difference
    ENCRYPT_MODEDECRYPT_MODEVARIABLE_NAME_MISMATCH
    3
    blowCipher.init(Cipher.DECRYPT_MODE, KEY);
                                                                                                  
    4
    ByteBuffer ciphertext = Base64.decode(source);
    4
    byte[] cleartext = new String(source).getBytes("UTF-8");
    4
    byte[] cleartext = new String(source).getBytes("UTF-8");
    5
    byte[] cipherArray = new byte[ciphertext.limit()];
    Differences
    Expression1Expression2Difference
    cleartextcipherArrayVARIABLE_NAME_MISMATCH
    new String(source).getBytes("UTF-8")new byte[ciphertext.limit()]TYPE_COMPATIBLE_REPLACEMENT
    5
    byte[] cipherArray = new byte[ciphertext.limit()];
                                                                  
    6
    ciphertext.get(cipherArray);
    5
    byte[] ciphertext = blowCipher.doFinal(cleartext);
    5
    byte[] ciphertext = blowCipher.doFinal(cleartext);
    7
    byte[] cleartext = blowCipher.doFinal(cipherArray);
    Differences
    Expression1Expression2Difference
    ciphertextcleartextVARIABLE_NAME_MISMATCH
    cleartextcipherArrayVARIABLE_NAME_MISMATCH
    7
    byte[] cleartext = blowCipher.doFinal(cipherArray);
    6
    return Base64.encode(ByteBuffer.wrap(ciphertext)).toString();
                                                                                                                                    
                                                                                                                
    8
    return new String(cleartext, "UTF-8").toCharArray();
    7
    return new String();
    7
    return new String();
    Preondition Violations
    Unmatched return new String();
                                                  
    Precondition Violations (2)
    Row Violation
    1Unmatched return new String();
    2Clone fragment #1 returns variables ciphertext , while Clone fragment #2 returns variables cipherArray, cleartext