今晚我必须制作密码才能使用 Node.js。我试过了,但我做不到。
怎么了 ?感谢您的帮助!!!
function encrypt(data,j) {
for(var i = 0, length = data.length; i<length; i++) {
j = data.charCodeAt(i);
//console.log(j);
String.fromCharCode(j);
process.stdout.write(j);
}
return j;
}
function decrypt(data) {
return data;
}
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdout.write('암호화할 문장을 입력(INPUT) : ' );
process.stdin.on('data',function(data,j) {
//data = data.trim();
process.stdout.write('평문 (uncoded) :' + data);
process.stdout.write('암호문(encrypt) :');
encrypt();
process.stdout.write('복호문(decrypt) :');
process.exit(1);
});
Microsoft Windows [Version 6.2.9200]
(c) 2007 Microsoft Corporation. All rights reserved.
C:\Users\Minji>cd ..
C:\Users>cd ..
C:\>cd workspace
C:\workspace>node 3112minji
암호화할 문장을 입력(INPUT) : abc
평문 (uncoded) :abc
암호문(encrypt) :
C:\workspace\3112minji.js:2
for(var i = 0, length = data.length; i<length; i++) {
^
TypeError: Cannot read property 'length' of undefined
at encrypt (C:\workspace\3112minji.js:2:30)
at ReadStream.<anonymous> (C:\workspace\3112minji.js:24:2)
at ReadStream.EventEmitter.emit (events.js:95:17)
at ReadStream.<anonymous> (_stream_readable.js:720:14)
at ReadStream.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:392:10)
at emitReadable (_stream_readable.js:388:5)
at readableAddChunk (_stream_readable.js:150:9)
at ReadStream.Readable.push (_stream_readable.js:113:10)
at TTY.onread (net.js:511:21)
C:\workspace>