-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring-cipher-rknarayan-vowel-strg-count.html
90 lines (76 loc) · 2.8 KB
/
string-cipher-rknarayan-vowel-strg-count.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<html>
<head>
<title>Caesar Cipher technique</title>
<style>
body {
background-color: cyan;
font: 14px;
}
</style>
<script>
function caesarCipher() {
let plaintext = prompt("Enter the text to encrypt:"); //Prompt the user for input
let shift = parseInt(prompt("Enter the shift pattern:")); //Prompt the user for shift pattern
let ciphertext = ""; //Initialize an empty string to store the encrypted text
for (let i = 0; i < plaintext.length; i++) {
let char = plaintext[i];
if (char.match(/[a-z]/i)) {
// Check if the character is a letter
let code = plaintext.charCodeAt(i);
if (code >= 65 && code <= 90) {
char = String.fromCharCode(((code - 65 + shift) % 26) + 65); // Uppercase letters
} else if (code >= 97 && code <= 122) {
char = String.fromCharCode(((code - 97 + shift) % 26) + 97); // Lowercase letters
}
}
ciphertext += char; // Add the encrypted character to the ciphertext string
}
alert("The encrypted text is: " + ciphertext); // Display the encrypted text using an alert
}
function rama() {
let name = prompt("Enter your full name:");
let nameArr = name.split(" ");
let firstName = nameArr[0];
let lastName = nameArr[nameArr.length - 1];
let middleInitials = "";
for (let i = 1; i < nameArr.length - 1; i++) {
middleInitials += nameArr[i].charAt(0) + ". ";
}
let processedName =
firstName.charAt(0) + ". " + middleInitials + lastName;
document.write(`
${processedName}
`);
}
function vowel() {
let str = prompt("Please enter a string to count vowel");
let result = countVowel(str);
function countVowel(str) {
let count = str.match(/[aeiou]/gi).length;
return count;
}
alert(result);
}
function strcount() {
let strr = prompt("Please enter a string to count");
let result = count_words(strr);
function count_words(strr) {
strr = strr.replace(/(^\s*)|(\s*$)/gi, "");
//convert 2 or more spaces to 1
strr = strr.replace(/[ ]{2,}/gi, " ");
// exclude newline with a start spacing
strr = strr.replace(/\n /, "\n");
let coount = strr.split(" ").length;
return coount;
}
alert(result);
}
</script>
</head>
<body>
<button onclick="caesarCipher()">click for Caesar Cipher technique</button>
<button onclick="rama()">click for Rama Krishna Narayana</button>
<button onclick="vowel()">click for vowels count</button>
<button onclick="strcount()">click for string count</button>
</body>
</html>