在javascript中加密邮件 [英] Encrypting a message in javascript

查看:73
本文介绍了在javascript中加密邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到一种方法来获取用户输入并迭代我创建的各种库作为全局变量。

/ b>



我尝试过:



I am having trouble finding out a way to take the users input and iterate over a variety of libraries I have created as global variables.
/b>

What I have tried:

/*GLOBAL VARIABLES*/

/* asks for the code you will encrypt into*/
var CODE = readLine("Which code would you like to encode in? morse, tap, ascii, binary, phonetic, substitution, or decode (Pick One: lowercase, NO symbols)");

/*I want this to loop and ask for one character at a time to encrypt against the libraries.*/
var MESSAGE = readLine("Message(*UPPERCASE ONLY*): ");


/*FORMAT: SPACE 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  1  2  3  4  5  6  7  8  9  0
   ARRAY:   0   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36*/

//USED TO ASSIGN AN INDEX NUMBER TO MESSAGE BEING ENCODED, EX. CODE: morse, MESSAGE: A, INDEX: 1 RETURNS: ._
var MIDX = [" ", "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", 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
];


var MORSE = [" ", "._", "_...", "_._.", "_..", ".", ".._.", "__.", "....", "..", ".___", "_._", "._..", "__", "_.", "___", ".__.", "__._", "._.", "...", "_", ".._", "..._", ".__", "_.._", "_.__", "__..", ".____", "..___", "...__", "...._", ".....", "_....", "__...", "___..", "____.", "_____"
];

function start(){
   if(CODE == "morse"){
       var me = morseEncode();
       println(me);
   }else{
       println("Sorry, Code language selected is not a valid input. Please try again.");
       
       
       
   }
   
}
function morseEncode(){
    var encoded = [];
    for(var i = 0; i < .length; i++){
        
    }
    return encoded;
    
    
}

推荐答案

您有重复的表格,英语和AsCII是相同的字符集。此外,您不需要为每种表类型使用特定方法,只需要一个方法来接收对源消息和转换表的引用。但是将单个字符翻译成字符串会使翻译成原文很难。大多数编码都是一对一的。而且,像大多数初学者一样,你正在努力做到一切。从只有一个翻译表的非常基本的程序开始。尝试几个不同的字符串,检查它们是否正确翻译。一旦你有逻辑工作,你可以添加其他表,大多数代码不需要任何更改。
You have duplicate tables, English and AsCII are the same character set. Also, you do not need a specific method for each table type, you just need one method which receives a reference to the source message and the translate table. But translating single characters to strings is going to make it difficult to translate back to the original; most encodings are on a one-to-one basis. And, like most beginners, you are trying to do everything at once. Start with a very basic program with just one translate table. Try a few different strings and check that they get translated correctly. Once you have the logic working you can add the other tables and most of the code should not need any changes.


这篇关于在javascript中加密邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆