2010-05-19 7 views

Répondre

0

J'ai créé une classe pour générer une chaîne phonétique comme ci-dessous.

USAGES:

chaîne Psw = "deT3f9y"

chaîne Téléphone = Phonetic.GetPhoneticPassword (Psw);

enter code here 

using System; en utilisant System.Collections.Generic; en utilisant System.Linq; en utilisant System.Web;

/// /// Description sommaire pour Phonetic /// public class Phonetic { publique phonétiques() { // // TODO : Ajouter la logique constructeur ici // }

public static string GetPhoneticPassword(string Passsord) 
{ 
    string PhoneticString = string.Empty; 
    char[] pswChar = Passsord.ToCharArray(); 
    foreach (char chr in pswChar) 
    { 
     if (PhoneticString == string.Empty) 
     { 
      PhoneticString = GetPhoneticSting(chr); 
     } 
     else 
     { 
      PhoneticString += " - " + GetPhoneticSting(chr); 
     } 
    } 

    return PhoneticString; 
} 


public static string GetPhoneticSting(char Chr) 
{ 
    string PhString= string.Empty; 

    string Newchar = Chr.ToString(); 

    switch (Newchar.ToLower()) 
    { 
     case "a": 
      PhString = "alpfa"; 
      break; 
     case "b": 
      PhString = "bravo"; 
      break; 
     case "c": 
      PhString = "charlie"; 
      break; 
     case "d": 
      PhString = "delta"; 
      break; 
     case "e": 
      PhString = "echo"; 
      break; 
     case "f": 
      PhString = "foxtrot"; 
      break; 
     case "g": 
      PhString = "golf"; 
      break; 
     case "h": 
      PhString = "hotel"; 
      break; 
     case "i": 
      PhString = "item"; 
      break; 
     case "j": 
      PhString = "juliet"; 
      break; 
     case "k": 
      PhString = "kilo"; 
      break; 
     case "l": 
      PhString = "lima"; 
      break; 
     case "m": 
      PhString = "mike"; 
      break; 
     case "n": 
      PhString = "november"; 
      break; 
     case "o": 
      PhString = "oscar"; 
      break; 
     case "p": 
      PhString = "papa"; 
      break; 
     case "q": 
      PhString = "queen"; 
      break; 
     case "r": 
      PhString = "romeo"; 
      break; 
     case "s": 
      PhString = "sugar"; 
      break; 
     case "t": 
      PhString = "tango"; 
      break; 
     case "u": 
      PhString = "uniform"; 
      break; 
     case "v": 
      PhString = "victor"; 
      break; 
     case "w": 
      PhString = "whiskey"; 
      break; 
     case "x": 
      PhString = "x-ray"; 
      break; 
     case "y": 
      PhString = "yankee"; 
      break; 
     case "z": 
      PhString = "zulu"; 
      break; 
     case "1": 
      PhString = "One"; 
      break; 
     case "2": 
      PhString = "Two"; 
      break; 
     case "3": 
      PhString = "Three"; 
      break; 
     case "4": 
      PhString = "Four"; 
      break; 
     case "5": 
      PhString = "Five"; 
      break; 
     case "6": 
      PhString = "Six"; 
      break; 
     case "7": 
      PhString = "Seven"; 
      break; 
     case "8": 
      PhString = "Eight"; 
      break; 
     case "9": 
      PhString = "Nine"; 
      break; 
     case "0": 
      PhString = "Zero"; 
      break; 
     default: 
      break; 
    } 

    if(CheckUpper(Chr.ToString())) 
    { 
     PhString = PhString.ToUpper(); 
    } 

    return PhString; 

} 

public static bool CheckUpper(string strCheck) 
{ 
    if(string.Compare(strCheck,strCheck.ToUpper())==0) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

0

avoir une table de consultation qui traduit les caractères en mots ('a' -> "alpha"), puis passez en revue les caractères du mot de passe généré, en recherchant le mot.

Questions connexes