The company Digital Secure Data
Transfer Solutions provides data encryption
and data sharing services. The process uses a
key for encryption when transmitting a list of
elements. To encrypt the list of elements, each
element in the list is replaced by the sum of
odd elements from the next/previous K
elements in the list. If the value of K is positive
then the previous K elements in the list are
selected. If the value of K is negative, then the
next Kelements in the list are selected. The
series of elements is considered in a cyclic
fashion for the last Kelements. If no odd
element in the next/previous k elements is
found then the element is replaced with a zero.
Write an algorithm to find the encrypted list.
Answers
Answer:
def list_encrypter(list_n):
encrypted_array =[]
for i in range(len(list_n)):
if list_n[i] % 2 == 0:
encrypted_array.append(sum(list_n[:int(i)]))
else:
encrypted_array.append(sum(list_n[int(i):]))
return encrypted_array
Explanation:
needs no explanation
JAVA CODE
package arrayproblems;
import java.util.ArrayList;
class Problem21 {
public static void main(String[] args) {
int N=25143;
int key=3;
String res="";
ArrayList array1=new ArrayList();
while(N!=0) {
array1.add(N%10);
N=N/10;
}
int[] array2=new int[array1.size()];
int k=0;
for(int i=array1.size()-1;i>=0;i--) {
array2[k]=(int) array1.get(i);
k=k+1;
}
for(int j=0;j<key-1;j++) {
int temp=array2[array2.length-1];
for(int i=array2.length-1;i>=1;i--) {
array2[i]=array2[i-1];
}
array2[0]=temp;
}
for(int i:array2) {
System.out.print(i+res);
}
}
}
#SPJ3