Answer:
Explanation:
#include <iostream>
#include <string>
#include<vector>
using namespace std;
vector<int> permute(vector<int>, vector<int>);
string encrypt(vector<int>s1 , vector<int> t1, string p);
string decrypt(vector<int>s1, vector<int> t1, string p);
int main() {
string plaintext = "cryptology";
string plaintext2 = "RC4";
vector<int> S(256);
vector<int> T(256);
int key[] = { 1,2,3,6 };
int key2[] = { 5,7,8,9 };
int tmp = 0;
for (int i = 0; i < 256;i++) {
S[i] = i;
T[i] = key[( i % (sizeof(key)/sizeof(*key)) )];
}
S = permute(S, T);
for (int i = 0; i < 256 ;i++) {
cout << S[i] << " ";
if ((i + 1) % 16 == 0)
cout << endl;
}
cout << endl;
string p = encrypt(S, T, plaintext);
cout << "Message: " << plaintext << endl;
cout << "Encrypted Message: " << " " << p << endl;
cout << "Decrypted Message: " << decrypt(S, T, p) << endl << endl;
tmp = 0;
for (int i = 0; i < 256;i++) {
S[i] = i;
T[i] = key2[(i % (sizeof(key) / sizeof(*key)))];
}
S = permute(S, T);
for (int i = 0; i < 256;i++) {
cout << S[i] << " ";
if ((i + 1) % 16 == 0)
cout << endl;
}
cout << endl;
p = encrypt(S, T, plaintext2);
cout << "Message: " << plaintext2 << endl;
cout << "Encrypted Msg: " << p << endl;
cout << "Decrypted Msg: "<<decrypt(S, T, p) << endl << endl;
return 0;
}
string decrypt(vector<int>s1, vector<int> t1, string p) {
int i = 0;
int j = 0;
int tmp = 0;
int k = 0;
int b;
int c;
int * plain = new int[p.length()];
string plainT;
for (int r = 0; r < p.length(); r++) {
i = (i + 1) % 256;
j = (j + s1[i]) % 256;
b = s1[i];
s1[i] = s1[j];
s1[j] = b;
tmp = (s1[i] + s1[j]) % 256;
k = s1[tmp];
c = ((int)p[r] ^ k);
plain[r] = c;
plainT += (char)plain[r];
}
return plainT;
}
string encrypt(vector<int>s1, vector<int> t1, string p) {
int i = 0;
int j = 0;
int tmp = 0;
int k = 0;
int b;
int c;
int * cipher = new int [p.length()];
string cipherT;
cout << "Keys Generated for plaintext: ";
for (int r = 0; r < p.length(); r++) {
i = (i + 1) % 256;
j = (j + s1[i]) % 256;
b = s1[i];
s1[i] = s1[j];
s1[j] = b;
tmp = (s1[i] + s1[j]) % 256;
k = s1[tmp];
cout << k << " ";
c = ((int)p[r] ^ k);
cipher[r] = c;
cipherT += (char)cipher[r];
}
cout << endl;
return cipherT;
}
vector<int> permute(vector<int> s1, vector<int> t1) {
int j = 0;
int tmp;
for (int i = 0; i< 256; i++) {
j = (j + s1[i] + t1[i]) % 256;
tmp = s1[i];
s1[i] = s1[j];
s1[j] = tmp;
}
return s1;
}
import java.util.Scanner;
public class JavaApplication41 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String language = scan.nextLine();
if (language.toLowerCase().equals("java")){
System.out.println("Awesome!");
}
else if (language.toLowerCase().equals("python")){
System.out.println("A very simple language!");
}
else if (language.toLowerCase().equals("ruby")){
System.out.println("Are you sure?");
}
else if (language.toLowerCase().equals("javascript")){
System.out.println("Easy enough");
}
else if (language.toLowerCase().equals("c")){
System.out.println("Cool!");
}
}
}
I hope this helps!
Everyone
B.
Citizens
C.
Adults
D.
Women
Correct Answer: citizens
Answer:
A. To ensure that management and the team has a clear picture of the state of the project
Explanation:
hope this helps!
Answer:
A
Explanation:
The assignment statementx = total (1, 1, 1);must result in:A. x being assigned the value 3 B. x being assigned the value 7C. x being assigned the value 5D. x being assigned the value 2E. x being assigned the value 0
Answer:
Explanation:
When you look at the assignment "x = total (1, 1, 1);", you can see that result, a and b all refers to 1. Then, you need to go to the function and check the conditions. The first condition is "if (a == 0)", it is not true because a is assigned to 1. Since that is not true, you need to go to the else part "else { return result * 3". That means the result of this function is going to give us 3 (because result variable equals to 1 initially). That is why x is going to be assigned as 3.
b. Base-T Ethernet
c. 10/100/1000 Ethernet
d. Token ring Ethernet
e. FDDI Ethernet
Answer: ANSWER is B I'm pretty sure
Explanation: hope this help
s :)
(b) Selection-sort on a sequence of size n.
(c) Merge-sort on a sequence of size n.
(d) Radix sort on a sequence of n integer keys, each in the range of[ 0, (n^3) -1]
(e) Find an element in a red-black tree that has n distinct keys.
Answer:
Answers explained below
Explanation:
(a) Construction of a heap of size n , where the keys are not known in advance.
Worst Case Time complexity - O(n log n)
Two procedures - build heap, heapify
Build_heap takes O(n) time and heapify takes O(log n) time. Every time when an element is inserted into the heap, it calls heapify procedure.
=> O(n log n)
(b) Selection-sort on a sequence of size n.
Worst Case Time complexity - O(n^2)
Selection sort finds smallest element in an array repeatedly. So in every iteration it picks the minimum element by comparing it with the other unsorted elements in the array.
=> O(n^2)
(c) Merge-sort on a sequence of size n.
Worst Case Time complexity - O(n log n)
Merge sort has two parts - divide and conquer. First the array is divided (takes O(1) time) into two halves and recursively each half is sorted (takes O(log n) time). Then both halves are combines (takes O(n) time).
=> O(n log n)
(d) Radix sort on a sequence of n integer keys, each in the range of[ 0 , (n^3) -1]
Worst Case Time complexity - O (n log b (a))
b - base of the number system, a - largest number in that range, n - elements in array
Radix sort is based on the number of digits present in an element of an array A. If it has 'd' digits, then it'll loop d times.
(e) Find an element in a red-black tree that has n distinct keys.
Worst Case Time complexity - O (log n)
Red-black tree is a self-balancing binary tree => The time taken to insert, delete, search an element in this tree will always be with respect to its height.
=> O(log n)