Image HereI'm trying to do this program where when I input a letter into an inputfield, the output text shows the letter after the input text letter, like a should be b, or b should be c, and so on. So I thought I could make an string array for the alphabet, and if the input letter is equal to the index of the looping array, than the result would be equal to the index + 1. I tried it and its just giving me the same thing as the input. Am I missing something?
public class Encryption : MonoBehaviour
{
public InputField input;
public Text output;
string inputText;
public Toggle L337Toggle;
public Toggle CharShiftToggle;
public Toggle DoubleCaseToggle;
public Toggle VowelToggle;
void Start()
{
L337Toggle.isOn = false;
CharShiftToggle.isOn = false;
DoubleCaseToggle.isOn = false;
VowelToggle.isOn = false;
}
private void Update()
{
inputText = input.text;
output.text = inputText;
IEncryption _textEncryption = new TextEncryption(inputText);
IEncryption _L337Encryption = new L337Encryption(_textEncryption);
IEncryption _CharShiftEncryption = new CharShiftEncryption(_textEncryption);
if (L337Toggle.isOn == true)
{
output.text = _L337Encryption.Encrypt();
}
else if (CharShiftToggle.isOn == true)
{
output.text = _CharShiftEncryption.Encrypt();
}
}
public interface IEncryption
{
string Encrypt();
}
public class TextEncryption : IEncryption
{
private string originalString;
public TextEncryption(string original)
{
originalString = original;
}
public string Encrypt()
{
Debug.Log("Encrypting Text");
return originalString;
}
}
public class L337Encryption : IEncryption
{
private IEncryption _encryption;
public L337Encryption(IEncryption encryption)
{
_encryption = encryption;
}
public string Encrypt()
{
Debug.Log("Encrypting L337 Text");
string result = _encryption.Encrypt();
result = result.Replace('a', '4').Replace('b', '8').Replace('e', '3').Replace('g', '6').Replace('h', '4').Replace('l', '1')
.Replace('o', '0').Replace('q', '9').Replace('s', '5').Replace('t', '7').Replace('A', '4').Replace('B', '8')
.Replace('E', '3').Replace('G', '6').Replace('H', '4').Replace('L', '1')
.Replace('O', '0').Replace('Q', '9').Replace('S', '5').Replace('T', '7');
return result;
}
}
public class CharShiftEncryption : IEncryption
{
private IEncryption _encryption;
public CharShiftEncryption(IEncryption encryption)
{
_encryption = encryption;
}
public string Encrypt()
{
Debug.Log("Encrypting Character Shift Text");
string result = _encryption.Encrypt();
string[] Letters=new string[] { "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" };
for (int i=0;i<Letters.Length;i++)
{
if (Letters[i] == result)
{
result = Letters[i + 1];
if (result == Letters[25])
{
result = Letters[0];
}
}
}
return result;
}
}
z? You also only check lower case letters.