Shyft was first written in 2019 in Python3 using the Eclipse IDE. (We have also used Pythonista on the iPad as a GREAT coding environment).
The JavaScript version was developed concurrently in our web-programming classes.
It was considerably easier to write in Python3!
Note: In the version shown below, we made extensive use of our 'TNT' utilities to do our work. This utility library has been growing over the last decade to help us do our work quickly and reliably.
Shyft: Eclipse Java Source Code
import java.awt.Color;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Random;
import java.util.Scanner;
/*
File: AlienLanguageDriver.java
Date: Sep 9, 2019
Time: 9:42:22 AM
Programmer: kp
Project: AlienLanguageProject-S7
Location (Option-Return copy/paste location):
/Users/kp/Desktop/2019-2020_Devmt/kp19-APCS-P4-T1/
* fromAPCS-P4/AlienLangJavaWS9-9-19/AlienLanguageProject-S7/
src/AlienLanguageDriver.java
Program Description:
Add a shifting number to allow encryption and decryptiong
Requirements/Sample Output:
Known Issues:
Found an error in TNTStringManip isUpperCaseLetter
Used the correctly-working isLowerCaseLetter function
Future Development:
*/
@SuppressWarnings("unused")
public class AlienLanguageDriver {
private static AlienLanguageDriver myDriverObj =
new AlienLanguageDriver();
//used to get className for termination statement
private static final Scanner KB = new Scanner(System.in);
//adjust app heading variables here
public static final String APP_TITLE = "Alien Language Driver";
private static final String STAGE_NO_STR = "7";
private static final String CURRENT_JAR =
"Java Archive: JavaTNT8-29-16.jar";
private static final char BORDER_SYMBOL = 'a';
private static final boolean SHOW_STANDARD_TIMESTAMP = true;
//main method is like the conductor of the symphony
public static void main(String[] args) {
TNTIO.printAppHeadingWithJarLine(APP_TITLE, STAGE_NO_STR,
CURRENT_JAR, BORDER_SYMBOL, SHOW_STANDARD_TIMESTAMP, 2);
//------------------------------------------------------------
//-------------------------------------------------
String phrase; //declaration
String defaultPhrase =
"\"What we learn with pleasure we never forget, HOPEFULLY.\"";
do {
phrase = TNTIO.guiPromptString("Enter your phrase",
"Alien Language App", true);
if(phrase.length()== 0) phrase = defaultPhrase;
System.out.println(phrase);
int shift =
TNTIO.guiPromptInt("Enter shifting constant",
"Alien Language", true);
System.out.println("Shifted by: " + shift);
String translation = translate(phrase, shift);
System.out.println(translation);
String retranslation = translate(translation, -shift);
System.out.println("Shifted back by: -" + shift);
System.out.println(retranslation);
System.out.println("");
}while(TNTIO.notDone("Alien Language App"));
System.out.println("Thanks for your input!");
//-------------------------------------------------
//-----------------------------------------------------------------------
TNTIO.printApplicationEndStatement(myDriverObj,'=');
KB.close();
}//end main method
public static String translate(String p) {
String vowels = "aeiou";
String consonants = "bcdfghjklmnpqrstvwxyz";
String alphabet = vowels + consonants;
String translation = "";
int lastNdx = p.length() - 1;
int shiftedNdx; //declaration
for(int ndx = 0; ndx <= lastNdx; ndx++) {
String symbol = p.substring(ndx, ndx+1);
//create a lower case version of symbol
String lcSymbol = symbol.toLowerCase();
String ltr;
if(alphabet.indexOf(lcSymbol) >= 0) {
if(vowels.indexOf(lcSymbol) >= 0) {
int vNdx = vowels.indexOf(lcSymbol);
shiftedNdx =
(vNdx + 1) % vowels.length();
ltr =
vowels.substring(shiftedNdx, shiftedNdx + 1);
}else {
int cNdx =
consonants.indexOf(lcSymbol);
shiftedNdx =
(cNdx + 1) % consonants.length();
ltr =
consonants.substring(shiftedNdx, shiftedNdx + 1);
}
/*EUREKA; DANGER WILL ROBINSON!
There is an error in isUpperCaseLetter function!!! */
if(!TNTStringManip.isLowerCaseLetter(symbol)) {
ltr = ltr.toUpperCase();
}
translation += ltr;
}else {
translation += symbol;
}
}//end for loop
return translation;
}//end translate method
//overloaded translate method
public static String translate(String p, int shift) {
String vowels = "aeiou";
String consonants = "bcdfghjklmnpqrstvwxyz";
String alphabet = vowels + consonants;
String translation = "";
int lastNdx = p.length() - 1;
int shiftedNdx; //declaration
for(int ndx = 0; ndx <= lastNdx; ndx++) {
String symbol = p.substring(ndx, ndx+1);
//create a lower case version of symbol
String lcSymbol = symbol.toLowerCase();
String ltr = "";
if(alphabet.indexOf(lcSymbol) >= 0) {
if(vowels.indexOf(lcSymbol) >= 0) {
int vNdx = vowels.indexOf(lcSymbol);
if(shift >= 0) {
shiftedNdx =
(vNdx + shift) % vowels.length();
}else {
shiftedNdx = vNdx + shift;
while(shiftedNdx < 0)
shiftedNdx += vowels.length();
}
ltr =
vowels.substring(shiftedNdx, shiftedNdx + 1);
}else {
int cNdx = consonants.indexOf(lcSymbol);
shiftedNdx = cNdx + shift;
if(shift >= 0) {
shiftedNdx =
(cNdx + shift) % consonants.length();
}else {
shiftedNdx = cNdx + shift;
while(shiftedNdx < 0)
shiftedNdx += consonants.length();
}
ltr =
consonants.substring(shiftedNdx, shiftedNdx + 1);
}
if(!TNTStringManip.isLowerCaseLetter(symbol)) {
ltr = ltr.toUpperCase();
}
translation += ltr;
}else {
translation += symbol;
}
}//end for loop
return translation;
}//end translate method
}//end driver class
//------SAMPLE OUTPUT-------------------------------------------------------------------------------------------------------------
/*
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
a Alien Language Driver - Stage 7 a
a Java Archive: JavaTNT8-29-16.jar a
a September 09, 2019 @ 01:28:13 PM a
a /Users/kp/Desktop/2019-2020_Devmt/... a
a ...kp19-APCS-P4-T1/fromAPCS-P4/AlienLangJavaWS9-9-19/... a
a ...AlienLanguageProject-S7/ a
a kp a
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
"What we learn with pleasure we never forget, HOPEFULLY."
Shifted by: 21
"Whet wi liern woth pliesari wi nivir furgit, HUPIFALLY."
Shifted back by: -21
"What we learn with pleasure we never forget, HOPEFULLY."
"What we learn with pleasure we never forget, HOPEFULLY."
Shifted by: 22
"Xjiv xo moisp xuvj qmoiteso xo powos gashov, JAQOGEMMZ."
Shifted back by: -22
"What we learn with pleasure we never forget, HOPEFULLY."
"What we learn with pleasure we never forget, HOPEFULLY."
Shifted by: 6
"Dpeb di sieyv dobp wsiezayi di viciy muynib, PUWIMASSG."
Shifted back by: -6
"What we learn with pleasure we never forget, HOPEFULLY."
"What we learn with pleasure we never forget, HOPEFULLY."
Shifted by: 5
"Cnaz ce reaxt cizn vreayuxe ce tebex loxmez, NOVELURRF."
Shifted back by: -5
"What we learn with pleasure we never forget, HOPEFULLY."
*/
Last update: 09/18/19