Epic Systems Interview Question
Software DevelopersCountry: United States
Interview Type: Written Test
Python version
def encrypt(aString):
string = aString.lower()
dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16,
'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
alphabet = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
result = ''
for i in range(len(string)):
temp = dict[string[i]] * 4
result += alphabet[(temp % 26) - 1]
return result
public static String multiplicative(String message, int number) {
String encrypted = "";
int letterValue;
for (int i = 0; i < message.length(); i++) {
// ascii 'a' starts at decimal value 97, b = 98, c = 99, etc
letterValue = (message.charAt(i) - 96) * number;
while (letterValue > 25) {
letterValue = letterValue % 26;
}
encrypted += (char) (letterValue + 96);
}
System.out.println(encrypted);
return encrypted;
}
}
c++ sol
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
string encryp(const string &s, int n){
string result{};
transform(s.cbegin(),s.cend(),back_inserter(result),[&](char c){
return char((((c-'A'+1)*n%26)+'A'-1));
});
return result;
}
int main(){
string s("BOYU");
cout<<encryp(s,6)<<endl;
}
import java.util.*;
public class Encryption {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap mp=new HashMap();
mp.put('a', 1); mp.put('b', 2); mp.put('c', 3); mp.put('d', 4); mp.put('e', 5); mp.put('f', 6); mp.put('g', 7);
mp.put('h', 8); mp.put('i', 9); mp.put('j', 10); mp.put('k', 11); mp.put('l', 12); mp.put('m', 13); mp.put('n', 14);
mp.put('o', 15); mp.put('p', 16); mp.put('q', 17); mp.put('r', 18); mp.put('s', 19); mp.put('t', 20);
mp.put('u', 21); mp.put('v', 22); mp.put('w', 23);mp.put('x', 24); mp.put('y', 25);mp.put('z', 26);
char[] alphabets={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
String str="SANTHOSH";
str=str.toLowerCase();
String output=null;
int temp;
for(int i=0;i<str.length();i++){
temp=(Integer) mp.get(str.charAt(i)) * 4;
if(temp>26){
temp=temp%26;
}
if(output==null){
output=Character.toString(alphabets[temp-1]);
}
else
{
output+=Character.toString(alphabets[temp-1]);
}
}
System.out.println("\n"+output);
}
}
1- Convert the text to Upper case
2- 'A' Char value in ASCII is 65, subtract 64 and you get your 1 ('B' = 66 , 66 - 2 = 64)
Here is the code
- Ajloun February 15, 2015