
Lefiya
Members-
Posts
6 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Lefiya's Achievements

Seeker (1/7)
0
Reputation
-
[OK] help for use .js to create TOTP, thx~ - (Moved)
Lefiya replied to Lefiya's topic in AutoIt General Help and Support
I mean, I use this UDF to create an OTP, but it produces a value that is not equal to the OTP 6 digits generated by the google authenticator. I also wrote a message below the article, but it still has not been resolved. So I want to call JS to complete it. Sorry, my English is not good, I am using GOOGLE translation... -
[OK] help for use .js to create TOTP, thx~ - (Moved)
Lefiya replied to Lefiya's topic in AutoIt General Help and Support
hi I have used this UDF But not working properly... -
If NOT $abb = 0 THe MSGBOX(0,0,'test') FileChangeDir(@ScriptDir) #NoTrayIcon #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Aut2Exe\Icons\icon.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=三益釀造-客戶資料管理系統 #AutoIt3Wrapper_Res_Description=三益釀造-客戶資料管理系統 #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2008-2017 sanyi.com.tw 版權所有。保留一切權利。 #AutoIt3Wrapper_Res_Language=1028 #AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 好的代碼: #include <Date.au3> 昏暗的$ code ='' $ code&='“use strict”; var sjcl = {cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function (a){this.toString = function(){return“CORRUPT:”+ this.message}; this.message = a},invalid:function(a){this.toString = function(){return“INVALID:” + this.message}; this.message = a},bug:function(a){this.toString = function(){return“BUG:”+ this.message}; this.message = a},notReady:function( a){this.toString = function(){return“NOT READY:”+ this.message}; this.message = a}}};' $ code&='“undefined”!= typeof module && module.exports &&(module.exports = sjcl);' $ code&='sjcl.bitArray = {bitSlice:function(a,b,c){a = sjcl.bitArray.g(a.slice(b / 32),32-(b&31))。slice(1); return void 0 === c?a:sjcl.bitArray.clamp(a,cb)},extract:function(a,b,c){var d = Math.floor(-bc&31); return((b + c) -1 ^ b) - 32 [b / 32 | 0] << 32-d ^ A [b / 32 + 1 | 0] >>> d:一個並[b / 32 | 0] >>> d? )&(1 << c)-1},concat:function(a,b){if(0 === a.length || 0 === b.length)返回a.concat(b); var c = a [a.length-1],d = sjcl.bitArray.getPartial(c);返回32 === d?a.concat(b):sjcl.bitArray.g(b,d,c | 0,a .slice(0,a.length-1))},bitLength:function(a){var b = a.length; return 0 ===' $ code&='b?0:32 *(b-1)+ sjcl.bitArray.getPartial(a [b-1])},clamp:function(a,b){if(32 * a.length <b )返回a; a = a.slice(0,Math.ceil(b / 32)); var c = a.length; b&= 31; 0 <c && b &&(a [c-1] = sjcl.bitArray.partial( b,a [c-1]&2147483648 >> b-1,1));返回a},partial:function(a,b,c){return 32 === a?b:(c?b | 0: b << 32-a)+ 0x10000000000 * a},getPartial:function(a){return Math.round(a / 0x10000000000)|| 32},equal:function(a,b){if(sjcl.bitArray.bitLength) (a)!== sjcl.bitArray.bitLength(b))return!1; var c = 0,d; for(d = 0; d <a.length; d ++)c | = a [d] ^ b [ d];返回0 ===' $ code&='c},g:function(a,b,c,d){var e; e = 0; for(void 0 === d &&(d = []); 32 <= b; b- = 32)d.push(c),c = 0; if(0 === b)返回d.concat(a); for(e = 0; e <a.length; e ++)d.push(c |一個並[e] >>> b),C = A [E] << 32-b; E =則為a.length一個[則為a.length-1]:0; A = sjcl.bitArray.getPartial(E); d.push(sjcl.bitArray.partial(b + a&31,32 <b + a?c:d.pop(),1)); return d},j:function(a,b){return [a [0 ] ^ b [0],A [1] ^ b [1],A [2] ^ b [2],[3] ^ b [3]]}};' $ code&='sjcl.codec.base32 = {e:“ABCDEFGHIJKLMNOPQRSTUVWXYZ234567”,fromBits:function(a,b){var c =“”,d,e = 0,g = sjcl.codec.base32.e,f = 0,K = sjcl.bitArray.bitLength(A);對於(d = 0; 5 * c.length <K)C + = g.charAt((F ^ A [d] >>> E)>>> ?27),5> E(F = A [d] << 5-E,E + = 27,d ++):(˚F<< = 5,E-= 5);對於(;!c.length&5 && b;) c + =“=”;返回c},toBits:function(a){a = a.replace(/ \ s | = / g,“”)。toUpperCase(); var b = [],c,d = 0 ,E = sjcl.codec.base32.e,G = 0,F;對於(C = 0;ç<則為a.length; C ++){F = e.indexOf(a.charAt(c)中);如果(0> f)拋出新的sjcl.exception.invalid(“這不是base32!”); 27 <d?(d- =' $ code&='27,b.push(g ^ f >>> d),g = f << 32-d):( d + = 5,g ^ = f << 32-d)} d&56 && b.push( sjcl.bitArray.partial(d&56,g,1)); return b}}; sjcl.hash.sha1 = function(a){a?(this.d = adslice(0),this.b = abslice(0) ,this.a = aa):this.reset()}; sjcl.hash.sha1.hash = function(a){return(new sjcl.hash.sha1).update(a).finalize()};' $ code&='sjcl.hash.sha1.prototype = {blockSize:512,reset:function(){this.d = this.h.slice(0); this.b = []; this.a = 0; return this},update:function(a){“string”=== typeof a &&(a = sjcl.codec.utf8String.toBits(a)); var b,c = this.b = sjcl.bitArray.concat(this .B,A); b = this.a; A = this.a = b + sjcl.bitArray.bitLength(A);對於(b = this.blockSize + b&-this.blockSize,b <= A; b + = this.blockSize)n(this,c.splice(0,16)); return this},finalize:function(){var a,b = this.b,c = this.d,b = sjcl.bitArray.concat (b,[sjcl.bitArray.partial(1,1)]);用於:(a = b.length個+ 2; A&15; ++)b.push(0);' $ code&='b.push(Math.floor(this.a / 0x100000000)); for(b.push(this.a | 0); b.length;)n(this,b.splice(0,16) )); this.reset(); return c},h:[1732584193,4023233417,2562383102,271733878,3285377520],i:[1518500249,1859775393,2400959708,3395469782]};' $ code&='function n(a,b){var c,d,e,g,f,k,m,l = b.slice(0),h = ad; e = h [0]; g = H [1]; F = H [2]; K為H [3]; M = H [4];對於(C = 0; 79> = C; C ++)16 <= C &&(升[C] =(升[C-3] ^ L [C-8] ^升並[c-14] ^升並[c-16])<< 1 |(L [C-3] ^ L [C-8] ^升並[c -14] ^升並[c-16])>>> 31),d = 19> = C G&F |〜克&K:39> = C G ^ F ^ K:?59> = C G&F | G&K | F&K :79> = c?g ^ f ^ k:void 0,d =(e << 5 | e >>> 27)+ d + m + l [c] + ai [Math.floor(c / 20)] | 0,M = K,K = F,F = G << 30 | G 2 >>>,G = E,E = d; H [0] = H [0] + E | 0; H [1] = H [1] + G | 0; H [2] = H [2] + F | 0; H [3] = H [3] + K | 0; H [4] = H [4] + M | 0}“ $ code&='sjcl.misc.hmac = function(a,b){this.f = b = b || sjcl.hash.sha256; var c = [[],[]],d,e = b。 prototype.blockSize / 32; this.c = [new b,new b]; a.length> e &&(a = b.hash(a)); for(d = 0; d <e; d ++)c [0] [d] = A [d] ^ 909522486,C [1] [d] = A [d] ^ 1549556828; this.c [0] .update(C [0]); this.c [1] .update( c [1])}; sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function(a){a =(new this.f(this.c [0]))。update (a).finalize(); return(new this.f(this.c [1]))。update(a).finalize()};' $ code&='function HOTP(K,C)' $ code&='{' $ code&='var key = sjcl.codec.base32.toBits(K);' $ code&='var count = [((C&0xffffffff00000000)>> 32),C&0xffffffff];' $ code&='var otplength = 6;' $ code&='var hmacsha1 = new sjcl.misc.hmac(key,sjcl.hash.sha1);' $ code&='var code = hmacsha1.encrypt(count);' $ code&='var offset = sjcl.bitArray.extract(code,152,8)&0x0f;' $ code&='var startBits = offset * 8;' $ code&='var endBits = startBits + 4 * 8;' $ code&='var slice = sjcl.bitArray.bitSlice(code,startBits,endBits);' $ code&='var dbc1 = slice [0];' $ code&='var dbc2 = dbc1&0x7fffffff;' $ code&='var otp = dbc2%Math.pow(10,otplength);' $ code&='var result = otp.toString();' $ code&='while(result.length <otplength)' $ code&='{' $ code&=“result ='0'+結果;” $ code&='}' $ code&='返回結果;' $ code&='}' 昏暗$ K ='LFLFMU2SGVCUIUCZKBMEKRKLIQ' Dim $ unixTime = _GetUnixTimeUTC() Dim $ counter = Int($ unixTime)/ 30 昏暗$ C =樓層($ counter) $ nJS = ObjCreate(“MSScriptControl.ScriptControl”) $ nJS.language =“JavaScript” $ nJS.addcode($代碼) $ nRegCreatePng = $ nJS.eval('HOTP(“'&$ K&'”,“'&$ C&'”)') MSGBOX(0,0,$ nRegCreatePng) Func _GetUnixTimeUTC() ; 返回自EPOCH以來的UTC秒數 本地$ aSysTimeInfo = _Date_Time_GetTimeZoneInformation() 本地$ utcTime =“” 本地$ sDate = _NowCalc() 如果$ aSysTimeInfo [0] = 2那麼 $ utcTime = _DateAdd('n',$ aSysTimeInfo [1] + $ aSysTimeInfo [7],$ sDate) 其他 $ utcTime = _DateAdd('n',$ aSysTimeInfo [1],$ sDate) 萬一 返回_DateDiff('s',“1970/01/01 00:00:00”,$ utcTime) ENDFUNC =============================================== 你好, 我怎樣才能在au3中使用這個js來創建totp?(沒有HTML,沒有hotp) 我嘗試使用JS但錯誤... 非常感謝〜 --------------- JavaScript的創建TOTP sjcl.js “嚴格使用”; var sjcl = {cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this .toString = function( ){return“CORRUPT:”+ this.message}; this.message = a},invalid:function(a){this.toString = function(){return“INVALID:”+ this.message}; this.message = a},bug:function(a){this.toString = function(){return“BUG:”+ this.message}; this.message = a},notReady:function(a){this。toString = function(){return“NOT READY:”+ this.message}; this.message = a}}}; “undefined”!= typeof module && module.exports &&(module.exports = sjcl); sjcl.bitArray = {bitSlice:function(a,b,c){a = sjcl.bitArray.g(a.slice(b / 32),32-(b&31))。slice(1); return void 0 == = c?a:sjcl.bitArray.clamp(a,cb)},extract:function(a,b,c){var d = Math.floor(-bc&31); return((b + c-1 ^ b) &-32一個並[b / 32 | 0] << 32-d ^ A [b / 32 + 1 | 0] >>> d:一個並[b / 32 | 0] >>> d)&(1 < <c)-1},concat:function(a,b){if(0 === a.length || 0 === b.length)返回a.concat(b); var c = a [a。 length-1],d = sjcl.bitArray.getPartial(c); return 32 === d?a.concat(b):sjcl.bitArray.g(b,d,c | 0,a.slice(0, a.length-1))},bitLength:function(a){var b = a.length; return 0 === b?0:32 *(b-1)+ sjcl.bitArray.getPartial(a [b-1])},clamp:function(a,b){if(32 * a.length <b)返回a; a = a.slice(0,Math.ceil(b / 32)); var c = a.length; b&= 31; 0 <c && b &&(a [c-1] = sjcl.bitArray.partial(b,a [c -1]&2147483648 >> b-1,1));返回a},partial:function(a,b,c){return 32 === a?b:(c?b | 0:b << 32- a)+ 0x10000000000 * a},getPartial:function(a){return Math.round(a / 0x10000000000)|| 32},等於:function(a,b){if(sjcl.bitArray.bitLength(a)!= = sjcl.bitArray.bitLength(b))return!1; var c = 0,d; for(d = 0; d <a.length; d ++)c | = a [d] ^ b [d];返回0 === c},g:函數(a,b,c,d){var e; e = 0; for(void 0 === d &&(d = []); 32 <= b; b- = 32)d。 push(c),c = 0; if(0 === b)返回d.concat(a); for(e = 0; e <a.length; e ++)d.push(c | a [e]> >> b),C = A [E] << 32-b; E =則為a.length一個[則為a.length-1]:0; A = sjcl.bitArray.getPartial(E); d.push(sjcl .bitArray.partial(b + a&31,32 <b + a?c:d.pop(),1)); return d},j:function(a,b){return [a [0] ^ b [0 ],A [1] ^ b [1],A [2] ^ b [2],[3] ^ b [3]]}}; sjcl.codec.base32 = {e:“ABCDEFGHIJKLMNOPQRSTUVWXYZ234567”,fromBits:function(a,b){var c =“”,d,e = 0,g = sjcl.codec.base32.e,f = 0,k = sjcl.bitArray.bitLength(A);對於(d = 0; 5 * c.length <K)C + = g.charAt((F ^ A [d] >>> E)>>> 27),5> ΔE(F = A [d] << 5-E,E + = 27,d ++):(˚F<< = 5,E-= 5);對於(; c.length&5 && b;!)C + =“=” ; return c},toBits:function(a){a = a.replace(/ \ s | = / g,“”)。toUpperCase(); var b = [],c,d = 0,e = sjcl。 codec.base32.e,g = 0,f; for(c = 0; c <a.length; c ++){f = e.indexOf(a.charAt(c)); if(0> f)拋出新的sjcl .exception.invalid(“這不是base32!”); 27 <d?(d- = 27,b.push(克^ F >>> d)中,g = F << 32-d):( d + = 5,G ^ = F << 32-d)} d&56 && b.push(sjcl.bitArray.partial (d&56,g,1)); return b}}; sjcl.hash.sha1 = function(a){a?(this.d = adslice(0),this.b = abslice(0),this.a = aa):this.reset()}; sjcl.hash.sha1.hash = function(a){return(new sjcl.hash.sha1).update(a).finalize()}; sjcl.hash.sha1.prototype = {blockSize:512,reset:function(){this.d = this.h.slice(0); this.b = []; this.a = 0; return this},update :function(a){“string”=== typeof a &&(a = sjcl.codec.utf8String.toBits(a)); var b,c = this.b = sjcl.bitArray.concat(this.b,a) ; b = this.a; A = this.a = b + sjcl.bitArray.bitLength(A);對於(b = this.blockSize + b&-this.blockSize,b <= A; b + = this.blockSize)N (this,c.splice(0,16)); return this},finalize:function(){var a,b = this.b,c = this.d,b = sjcl.bitArray.concat(b,[sjcl .bitArray.partial(1,1)]);用於:(a = b.length個+ 2; A&15; ++)b.push(0); b.push(Math.floor(this.a / 0x100000000));對於(b.push(this.a | 0); b.length個;)N(此,b.splice(0,16));此。 reset(); return c},h:[1732584193,4023233417,2562383102,271733878,3285377520],i:[1518500249,1859775393,2400959708,3395469782]}; 函數n(a,b){var c,d,e,g,f,k,m,l = b.slice(0),h = ad; e = h [0]; g = h [1]; F = H [2]; K為H [3]; M = H [4];對於(C = 0; 79> = C; C ++)16 <= C &&(升並[c] =(L [C-3 ] ^ L [C-8] ^升並[c-14] ^升並[c-16])<< 1 |(L [C-3] ^ L [C-8] ^升並[c-14] ^升[C-16])>>> 31),d = 19> = C G&F |〜克&K:39> = C G ^ F ^ K:59> = C G&F | G&K | F&K:?79> = C ?g ^ f ^ k:void 0,d =(e << 5 | e >>> 27)+ d + m + l [c] + ai [Math.floor(c / 20)] | 0,m = K,K = F,F = G << 30 | G 2 >>>,G = E,E = d; H [0] = H [0] + E | 0; H [1] = H [1] + G | 0; H [2] = H [2] + F | 0; H [3] = H [3] + K | 0; H [4] = H [4] + M | 0} sjcl.misc.hmac = function(a,b){this.f = b = b || sjcl.hash.sha256; var c = [[],[]],d,e = b.prototype.blockSize / 32 ; this.c = [new b,new b]; a.length> e &&(a = b.hash(a)); for(d = 0; d <e; d ++)c [0] [d] = a [d] ^ 909522486,C [1] [d] = A [d] ^ 1549556828; this.c [0] .update(C [0]); this.c [1] .update(C [1]) sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function(a){a =(new this.f(this.c [0]))。update(a).finalize (); return(new this.f(this.c [1]))。update(a).finalize()}; totp.js (功能() { “嚴格使用”; / *全局文檔,sjcl * / 功能HOTP(K,C) { var key = sjcl.codec.base32.toBits(K); // Count是64位長。請注意JavaScript按位操作 //在這種情況下,MSB實際上是0。 var count = [((C&0xffffffff00000000)>> 32),C&0xffffffff]; var otplength = 6; var hmacsha1 = new sjcl.misc.hmac(key, sjcl.hash.sha1); var code = hmacsha1.encrypt(count); var offset = sjcl.bitArray.extract(code, 152, 8) & 0x0f; var startBits = offset * 8; var endBits = startBits + 4 * 8; var slice = sjcl.bitArray.bitSlice(code, startBits, endBits); var dbc1 = slice[0]; var dbc2 = dbc1 & 0x7fffffff; var otp = dbc2 % Math.pow(10, otplength); var result = otp.toString(); while (result.length < otplength) { result = '0' + result; } return result; } // // UI Functions // function GenerateHOTP() { var secret = document.getElementById('secret').value; var counterEl = document.getElementById('hotpcounter'); var counter = parseInt(counterEl.value, 10); var otp = HOTP(secret, counter); var passwordEl = document.getElementById('hotpresult'); while (passwordEl.hasChildNodes()) { passwordEl.removeChild(passwordEl.firstChild); } passwordEl.textContent = "HOTP: " + otp; counterEl.value = counter + 1; } function GenerateTOTP() { var secret = document.getElementById('secret').value; var ctime = Math.floor((new Date() - 0) / 30000); var counterEl = document.getElementById('totpcounter'); counterEl.value = ctime; var otp = HOTP(secret, ctime); var passwordEl = document.getElementById('totpresult'); while (passwordEl.hasChildNodes()) { passwordEl.removeChild(passwordEl.firstChild); } passwordEl.textContent = "TOTP: " + otp; } function ConfigureHandlers() { var el = document.getElementById('generateotp'); el.addEventListener('click', GenerateHOTP, false); setInterval(GenerateTOTP, 1000); GenerateHOTP(); GenerateTOTP(); } document.addEventListener('DOMContentLoaded', ConfigureHandlers, false); } )(); index.html <!DOCTYPE html> <html manifest="hotp.appcache"> <head> <meta charset="UTF-8"/> <title>HOTP/TOTP Demonstration</title> <script src="sjcl.js"></script> <script src="totp.js"></script> <style> label { display: inline-block; min-width: 12em; } input { min-width: 30em !important; } .hotpresult:before { content: "HOTP: "; } .totpresult:before { content: "TOTP: "; } </style> </head> <body> <form id="otpinputs"> <label for="secret">Secret (Base32)</label> <input id="secret" type="text" value="LFLFMU2SGVCUIUCZKBMEKRKLIQ"/> <br /> <label for="hotpcounter">HOTP Counter (next value)</label> <input id="hotpcounter" type="text" value="0"/> <br /> <label for="totpcounter">TOTP Counter</label> <input id="totpcounter" type="text" value=""/> </form> <button id="generateotp">Generate HOTP</button> <div id="hotpresult"> </div> <div id="totpresult"> </div> </body> </html> -------------------- my try code1: $nJS.addcode($code) $nJS^ ERROR MsgBox(0,0,Totp_JS('LFLFMU2SGVCUIUCZKBMEKRKLIQ')) Func Totp_JS($Key) Local $code $code &= '(function()' & @CRLF $code &= '{' & @CRLF $code &= '"use strict";' & @CRLF $code &= 'function GenerateTOTP()' & @CRLF $code &= '{' & @CRLF $code &= "var secret =" & $Key & ";" & @CRLF $code &= 'var ctime = Math.floor((new Date() - 0) / 30000);' & @CRLF $code &= "var counterEl = document.getElementById('totpcounter');" & @CRLF $code &= 'counterEl.value = ctime;' & @CRLF $code &= 'var otp = HOTP(secret, ctime);' & @CRLF $code &= "var passwordEl = document.getElementById('totpresult');" & @CRLF $code &= 'while (passwordEl.hasChildNodes())' & @CRLF $code &= '{' & @CRLF $code &= 'passwordEl.removeChild(passwordEl.firstChild);' & @CRLF $code &= '}' & @CRLF $code &= 'passwordEl.textContent = "TOTP: " + otp;' & @CRLF $code &= '}' & @CRLF $code &= 'function ConfigureHandlers()' & @CRLF $code &= '{' & @CRLF $code &= "var el = document.getElementById('generateotp');" & @CRLF $code &= "el.addEventListener('click', GenerateHOTP, false);" & @CRLF $code &= 'setInterval(GenerateTOTP, 1000);' & @CRLF $code &= 'GenerateTOTP();' & @CRLF $code &= '}' & @CRLF $code &= "document.addEventListener('DOMContentLoaded', ConfigureHandlers, false);" & @CRLF $code &= '}' & @CRLF $code &= ')();' & @CRLF $nJS = ObjCreate("ScriptControl") $nJS.language = "JavaScript" $nJS.addcode($code) $nTotp_JS = $nJS.Run("GenerateTOTP") Return $nTotp_JS EndFunc my try code2: $nJS.addcode($code) $nJS^ ERROR #include <Date.au3> Func js() Local $code ;;TOTP(K,C) ;;K = Key ;;C = (T - T0) / X ;;T = Unix ;; T0 = 0 ;; X = 30(秒) $ T = _DateDiff('s',“1970/01/01 08:00:00”,_ NowCalc()) $ X = 30 $ K ='LFLFMU2SGVCUIUCZKBMEKRKLIQ“ $ C = $ T / $ X. $ code = FileRead(“totp.js”) $ nJS = ObjCreate(“MSScriptControl.ScriptControl”) $ nJS.language =“JavaScript” $ nJS.addcode($代碼) $ nReg = $ nJS.eval('function HOTP(“'&$ K&'”,“'&$ C&'”)') 返回$ nReg ENDFUNC; ==> js MSGBOX(0,0,JS())
-
Lefiya reacted to a post in a topic: Google Authenticator Implementation
-
thank you~ for everything^^ i think maybe demo site server time and i different... Can i inquire you about Your location?(UTC+?) i want to try it~ thank you very much~
-
Lefiya reacted to a post in a topic: Google Authenticator Implementation
-
Thank you for your heip ^^ but i understand about how to use... Can you heip me again? thx~ And why use >> ConsoleWrite(_GenerateTOTP("JBSWY3DPEHPK3PXP") & @CRLF) == 8 What mean about 8? The site OTP <> code OTP... Video: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiListBox.au3> #include <GuiComboBox.au3> #include <GuiListView.au3> #include <Array.au3> #include <Misc.au3> #include <Process.au3> #include <GUIConstants.au3> #include <EditConstants.au3> #Include <GuiEdit.au3> #include <APIConstants.au3> #include <GDIPlus.au3> #include <Memory.au3> #include <WinAPIEx.au3> #include <MsgBoxConstants.au3> #include <Access.au3> #include <Thread.au3> #include <GuiIPAddress.au3> #include <Crypt.au3> #include <Excel.au3> #include <GuiMenu.au3> #include <_HMAC.au3> #include <_GAuth.au3> #include <math.au3> #include <Clipboard.au3> Dim $a, $n Opt("GUIOnEventMode", 1) $Form1 = GUICreate('GAuth', 500, 500, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_EVENT_CLOSE") $Edit1 = GUICtrlCreateEdit('',20,20,460,410) GUICtrlCreateButton('Grt OTP',200,450,100,30,$BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "_RUN") GUISetState(@SW_SHOW) _SetWindowPos($Form1,-1,-1,-1,-1,$HWND_TOPMOST,$SWP_NOMOVE+$SWP_NOSIZE);;TOP While 1 Sleep(100) WEnd Func GUI_EVENT_CLOSE() Exit EndFunc Func _RUN() Dim $unixTime = _GetUnixTimeUTC() Dim $time = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC Dim $easy0 = ConsoleWrite(_GenerateTOTP("JBSWY3DPEHPK3PXP") & @CRLF) Dim $easy1 = _GenerateTOTP("JBSWY3DPEHPK3PXP", True, Default, 30, 6) Dim $counter = Int($unixTime) / 30 Dim $T = Floor($counter) Dim $key = _HMAC_SHA1('JBSWY3DPEHPK3PXP',$T) Dim $Offset = StringRight($key,1) If StringRegExp($Offset,'[a-fA-F]',0) = 1 Then If $Offset = 'A' Then $Offset = '10' If $Offset = 'B' Then $Offset = '11' If $Offset = 'C' Then $Offset = '12' If $Offset = 'D' Then $Offset = '13' If $Offset = 'E' Then $Offset = '14' If $Offset = 'F' Then $Offset = '15' EndIf $m = StringSplit($key,'x') $Sbits = StringMid($m[2],$Offset,8) ;;---hex $Sbits2 = StringMid ($Sbits,5,2) & StringMid ($Sbits,3,6) ;;---hex to dec Dim $s = 7 Dim $tenVal = Null, $num = Null, $num2 = Null For $i = 0 to 7 $num = StringMid ($Sbits2,$i+1,1) If StringRegExp($num,'[a-fA-F]',0) = 1 Then If $num = 'A' Then $num = '10' If $num = 'B' Then $num = '11' If $num = 'C' Then $num = '12' If $num = 'D' Then $num = '13' If $num = 'E' Then $num = '14' If $num = 'F' Then $num = '15' EndIf $num2 = $num * 16 ^ $s $s -= 1 $tenVal += $num2 ;;dec Next $Digit = 6 ;;6 digits key $OTP = Mod($tenVal,10^$Digit)-1 ;;---Number of digits: 6 If StringLen($OTP) < 6 Then $a = 6 - StringLen($OTP) If $a = 6 Then $OTP = '000000' & Mod($tenVal,10^6) If $a = 5 Then $OTP = '00000' & Mod($tenVal,10^6) If $a = 4 Then $OTP = '0000' & Mod($tenVal,10^6) If $a = 3 Then $OTP = '000' & Mod($tenVal,10^6) If $a = 2 Then $OTP = '00' & Mod($tenVal,10^6) If $a = 1 Then $OTP = '0' & Mod($tenVal,10^6) EndIf GUICtrlSetData($Edit1, 'Basic' & @CRLF & '===================' & @CRLF & '$unixTime: ' & $unixTime & @CRLF & 'unix to time: ' & _DateAdd('s',$unixTime,"1970/01/01 00:00:00") & @CRLF & '$time: ' & $time & @CRLF & @CRLF & 'wraithdu code' & @CRLF & '===================' & @CRLF & 'ConsoleWrite(_GenerateTOTP("JBSWY3DPEHPK3PXP") & @CRLF):' & $easy0 & @CRLF & '_GenerateTOTP:' & $easy1 & @CRLF & @CRLF & 'my code' & @CRLF & '===================' & @CRLF & '$counter: ' & $counter & @CRLF & '$T: ' & $T & @CRLF & '$key: ' & $key & @CRLF & '$Sbits: ' & $Sbits & @CRLF & '$tenVal: ' & $tenVal & @CRLF & '$OTP: ' & $OTP) EndFunc Func _SetWindowPos($hWnd,$x,$y,$cX,$cY,$hWndInsertAfter = -1,$wFlags = 1) DllCall("user32.dll","long","SetWindowPos","long",$hWnd,"long",$hWndInsertAfter,"long",$x,"long",$y,"long",$cX,"long",$cY,"long",$wFlags) EndFunc;==>_SetWindowPos
-
嗨〜 我將此UDF用於TOTP,但OTP不正確。 我找不到錯誤,你能幫幫我嗎?謝謝〜 (我在UTC + 8) 此代碼生成值<> http://gauth.apps.gbraad.nl/ value 我也使用谷歌 身份驗證器 <> http://gauth.apps.gbraad.nl/ 值。 昏暗$ OTP = _GenerateTOTP (“JBSWY3DPEHPK3PXP” ,真,默認,30 ,6 ) Translation: Hi~ I use this UDF for TOTP, but the OTP is incorrect. I can't find the error, can you help me? Thank you~ (I am at UTC + 8) This code generates a value <> http://gauth.apps.gbraad.nl/ value I also use the Google Authenticator <> http://gauth.apps.gbraad.nl/ value. Dim $ OTP = _GenerateTOTP ("JBSWY3DPEHPK3PXP", true, default, 30, 6)