Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #24 - Java, JavaScript y TypeScript #3824

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Retos/Reto #24 - CIFRADO CÉSAR [Fácil]/java/Qv1ko.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Qv1ko {

public static void main(String[] args) {
encrypt("Lorem ipsum dolor sit amet.", 6);
decrypt("gjmzh dknph yjgjm ndo vhzo.", 21);
}

private static void encrypt(String text, int number) {
String result = "";
char[] letters = text.toLowerCase().toCharArray();
for(char letter : letters) {
result += (char)((letter < 97 || letter > 122)? letter : (letter + number > 122)? letter + number - 26 : letter + number);
}
System.out.println(result);
}

private static void decrypt(String cesar, int number) {
String result = "";
char[] letters = cesar.toLowerCase().toCharArray();
for(char letter : letters) {
result += (char)((letter < 97 || letter > 122)? letter : (letter - number < 97)? letter - number + 26 : letter - number);
}
System.out.println(result);
}

}
20 changes: 20 additions & 0 deletions Retos/Reto #24 - CIFRADO CÉSAR [Fácil]/javascript/Qv1ko.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
encrypt("Lorem ipsum dolor sit amet.", 6)
decrypt("gjmzh dknph yjgjm ndo vhzo.", 21)

function encrypt(text, number) {
let result = ""
const letters = text.toLowerCase().split("")
letters.forEach(letter => {
result += (letter < "a" || letter > "z") ? letter : (letter.charCodeAt(0) + number > 122)? String.fromCharCode(letter.charCodeAt(0) + number - 26) : String.fromCharCode(letter.charCodeAt(0) + number)
})
console.log(result)
}

function decrypt(cesar, number) {
let result = ""
const letters = cesar.toLowerCase().split("")
letters.forEach(letter => {
result += (letter < "a" || letter > "z")? letter : (letter.charCodeAt(0) - number < 97)? String.fromCharCode(letter.charCodeAt(0) - number + 26) : String.fromCharCode(letter.charCodeAt(0) - number)
})
console.log(result)
}
20 changes: 20 additions & 0 deletions Retos/Reto #24 - CIFRADO CÉSAR [Fácil]/typescript/Qv1ko.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
encrypt("Lorem ipsum dolor sit amet.", 6)
decrypt("gjmzh dknph yjgjm ndo vhzo.", 21)

function encrypt(text: string, numberEncrypt: number): void {
let result = ""
const letters = text.toLowerCase().split("")
letters.forEach((letter: string) => {
result += (letter < "a" || letter > "z")? letter : (letter.charCodeAt(0) + numberEncrypt > 122) ? String.fromCharCode(letter.charCodeAt(0) + numberEncrypt - 26) : String.fromCharCode(letter.charCodeAt(0) + numberEncrypt)
})
console.log(result)
}

function decrypt(cesar: string, numberDecrypt: number): void {
let result = ""
const letters = cesar.toLowerCase().split("")
letters.forEach((letter: string) => {
result += (letter < "a" || letter > "z")? letter : (letter.charCodeAt(0) - numberDecrypt < 97) ? String.fromCharCode(letter.charCodeAt(0) - numberDecrypt + 26) : String.fromCharCode(letter.charCodeAt(0) - numberDecrypt)
})
console.log(result)
}