0% found this document useful (0 votes)
2 views1 page

Encryption

This document contains a Java class named 'Encryption' that implements a Caesar Shift cipher for encrypting text. The method 'encryptMessage' takes a message and a shift key as inputs, shifting each letter by the specified key while leaving non-letter characters unchanged. The encryption is performed using a predefined alphabet of uppercase letters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Encryption

This document contains a Java class named 'Encryption' that implements a Caesar Shift cipher for encrypting text. The method 'encryptMessage' takes a message and a shift key as inputs, shifting each letter by the specified key while leaving non-letter characters unchanged. The encryption is performed using a predefined alphabet of uppercase letters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/**

* To encrypt a given text using a Ceasar Shift cipher.


*
* Aksh Ladegaonkar
* APR 10, 2025
*/
public class Encryption {
public static String encryptMessage(String message, int shiftKey) {
StringBuilder encryptedMessage = new StringBuilder();
final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

for (int i = 0; i < message.length(); i++) {


char currentChar = message.charAt(i);
if (Character.isLetter(currentChar)) {
int charIndex = ALPHABET.indexOf(currentChar);
int shiftedIndex = (charIndex + shiftKey) % 26;
encryptedMessage.append(ALPHABET.charAt(shiftedIndex));
} else {
encryptedMessage.append(currentChar); // Non-letter characters
remain unchanged
}
}
return encryptedMessage.toString();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy