Agung Code
2 min readJun 25, 2022

Check String and Reverse String C# (AgungCode.Com)

You are provided with the so-called “check string”, where:
The First character is a digit that represents the number of uppercase
symbols in the correct password
the next 3 characters are the last 3 characters of the correct password
in reverse order
the last characters represent the sum of all digits in the password

Input : [“Testpassword”, “myPassword#4”], “1dro0”
Output : Testpassword

Input : [“p@ssWORD2”, “40passWORD30”, “PAsS5word”],“4dro5"
Output : PAsS5word

Input : [“MytestPassword5”,“fuckPassword2#$%”],“2%$#2”
Output: fuckPassword2#$%

static void Main(string[] args)

{

string[] Password = {“MytestPassword5”,“fuckPassword2#$%” };

string result = password(Password, “2%$#2”);

Console.Write(“Output : “);

Console.Write(result);

Console.ReadKey();

}

public static string password(string [] passwords, string checkString){

string kata =””;

int totalSame=0;

string newkata =””;

string Result =””;

int countUpperCase = 0;

string kataTerbalik = “”;

int i;

//Array.ForEach(passwords, Console.WriteLine);

Console.WriteLine(“[{0}]”, string.Join(“, “, passwords));

for (i=0; i < passwords.Length; i++)

{

//get Word

//Console.WriteLine(passwords[i]);

kata = passwords[i];

//kata = passwords[i].Substring(passwords[i].Length — 3, 3);

newkata = “”;

foreach (char c in kata)

{

//Check Car in contain in checkString

if (checkString.Contains(c))

{

//set new word

//Console.WriteLine(c);

newkata = newkata + c;

//get count

totalSame++;

}

if (char.IsUpper(c)) {

countUpperCase++;

}

}

if (newkata.Length > 0) {

kataTerbalik = reverse(newkata).Substring(newkata.Length-3, 3);

}

//Console.WriteLine(“KATA TERBALIK”);

//Console.WriteLine(kataTerbalik);

//Console.WriteLine(“KATA AWAL”);

//Console.WriteLine(kata);

//Console.WriteLine(“KATA SUBS”);

//Console.WriteLine(kata.Substring(kata.Length — 3, 3));

if (kata.Substring(kata.Length — 3, 3) == kataTerbalik.Trim() && kata.Any(char.IsUpper))

{

Result = kata;

}

}

//Contains

//if (kata.Contains(kataTerbalik.Trim()) && countUpperCase > 1)

//{

// Result = kata;

//}

//3 Last Char

return Result;

}

public static string reverse(string kata) //membalikan

{

char[] data = kata.ToCharArray();

char tampung;

for(int i=0;i<data.Length;i++){

tampung = data[i];

data[i] = data[data.Length-i-1];

data[data.Length-i- 1] = tampung;

}

return new String(data);

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Agung Code
Agung Code

Written by Agung Code

0 Followers

Programmer, System Analyst, Blogger, Content Writer

No responses yet

Write a response