network phantom
Addict
- Joined
- Oct 4, 2016
- Posts
- 53
- Reaction
- 8
- Points
- 87
- Age
- 24
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
na code ko na po yung problem ko po is yung sa number nalangeasy. array lang yan. find value at specified index array
source code mo nga?na code ko na po yung problem ko po is yung sa number nalang
source code mo nga?
source code mo nga?
pwede po ba patulong ? using array pwede din daw loopingeasy. array lang yan. find value at specified index array
create two arrays. one for plaintext and one is for encrypted.pwede po ba patulong ? using array pwede din daw looping
using System;
public class Program
{
static string letters = "abcdefghijklmnopqrstuvwxyz";
static string numbers = "0123456789";
static string inputText = "";
public static void Main()
{
Console.Write("Enter text: ");
inputText = Console.ReadLine();
Console.WriteLine("Encrypted: " + Cipher(inputText.ToLower(), 8));
Console.Write("Enter text to decrypt: ");
inputText = Console.ReadLine();
Console.WriteLine("Decrypted: " + Cipher(inputText.ToLower(), -8));
}
public static string Cipher(string text, int num)
{
string cipheredText = "";
int numMove = 0;
for (int i = 0; i < text.Length; i++)
{
if (Char.IsWhiteSpace(text[i]))
{
cipheredText += ' ';
}
else
{
if (Char.IsNumber(text[i]))
{
numMove = numbers.IndexOf(text[i]) + num;
if (numMove > numbers.Length - 1)
{
numMove = numMove % numbers.Length;
}
else if (numMove < 0)
{
while (numMove < 0)
{
numMove = numbers.Length + numMove;
}
}
cipheredText += numbers[numMove];
}
else
{
numMove = letters.IndexOf(text[i]) + num;
if (numMove > letters.Length - 1)
{
numMove = numMove % letters.Length;
}
else if (numMove < 0)
{
while (numMove < 0)
{
numMove = letters.Length + numMove;
}
}
cipheredText += letters[numMove];
}
}
}
if (num < 0)
{
return cipheredText;
}
else
{
return cipheredText.ToUpper();
}
}
}
maraming salamat poPag-aralan mabuti ang code.
This might not be the most efficient code but the outputs are correct.
Maganda dito pwede mo din iask ang user to replace 8. Para hindi 8 lang ang ciphering. Pwede any integer.
C#:using System; public class Program { static string letters = "abcdefghijklmnopqrstuvwxyz"; static string numbers = "0123456789"; static string inputText = ""; public static void Main() { Console.Write("Enter text: "); inputText = Console.ReadLine(); Console.WriteLine("Encrypted: " + Cipher(inputText.ToLower(), 8)); Console.Write("Enter text to decrypt: "); inputText = Console.ReadLine(); Console.WriteLine("Decrypted: " + Cipher(inputText.ToLower(), -8)); } public static string Cipher(string text, int num) { string cipheredText = ""; int numMove = 0; for (int i = 0; i < text.Length; i++) { if (Char.IsWhiteSpace(text[i])) { cipheredText += ' '; } else { if (Char.IsNumber(text[i])) { numMove = numbers.IndexOf(text[i]) + num; if (numMove > numbers.Length - 1) { numMove = numMove % numbers.Length; } else if (numMove < 0) { while (numMove < 0) { numMove = numbers.Length + numMove; } } cipheredText += numbers[numMove]; } else { numMove = letters.IndexOf(text[i]) + num; if (numMove > letters.Length - 1) { numMove = numMove % letters.Length; } else if (numMove < 0) { while (numMove < 0) { numMove = letters.Length + numMove; } } cipheredText += letters[numMove]; } } } if (num < 0) { return cipheredText; } else { return cipheredText.ToUpper(); } } }
my problem is the prof want us to use only string, array and loopWhat is the problem? How to write the code or you don't know the algorithm?
State the algorithm and I will code it for you. If it's the algorithm, then sorry I can't spoon fed that to you.
my problem is the prof want us to use only string, array and loop. the problem while he is teaching is the language barrier. he is not good in teaching using english
my problem is the prof want us to use only string, array and loop
yes we are allowed to use arithmeticSo you are not allowed to use arithmetic?
using System;
public class Program {
static string input = "";
public static void Main() {
Console.Write("Enter plaintext numbers: ");
input = Console.ReadLine();
Console.WriteLine("encrypted numbers: " + Encrypt(input));
Console.Write("Enter encrypted numbers: ");
input = Console.ReadLine();
Console.WriteLine("Plaintext numbers: " + Decrypt(input));
}
public static string Encrypt(string input) {
string encrypted = "";
foreach (char c in input) {
int encoded = int.Parse(c.ToString()) - 2;
encoded = encoded < 0 ? encoded + 10 : encoded;
encrypted += encoded.ToString();
}
return encrypted;
}
public static string Decrypt(string input) {
string decrypted = "";
foreach (char c in input) {
int decoded = int.Parse(c.ToString()) + 2;
decoded = decoded > 9 ? decoded - 10 : decoded;
decrypted += decoded.ToString();
}
return decrypted;
}
}
Mono C# compiler version 4.6.2.0
mcs -out:main.exe main.cs
mono main.exe
Enter plaintext numbers: 0123456789
encrypted numbers: 8901234567
Enter encrypted numbers: 8901234567
Plaintext numbers: 0123456789