Advertisement
yy981

Winbatch to Javascript by ChatGPT

May 18th, 2023 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. -------------------------Winbatch-------------------------
  2. @echo off
  3. chcp 65001
  4.  
  5.  
  6. echo [処理に時間がかかる場合があります]
  7. echo.
  8.  
  9. :@3b_start
  10. set @3b_type=
  11. set @3b_loop=1
  12. set /p @3b_u_loop=文字数を入力してください:
  13. set @3b_output=
  14. set @3b_nul=
  15.  
  16. echo 1. 数字
  17.  
  18. echo 2. アルファベット小文字
  19.  
  20. echo 3. アルファベット大文字
  21.  
  22. echo 4. アルファベット小文字+アルファベット大文字
  23.  
  24. echo 5. 数字+アルファベット小文字
  25.  
  26. echo 6. 数字+アルファベット大文字
  27.  
  28. echo 7. 数字+アルファベット小文字+アルファベット大文字
  29.  
  30. :@3b_restart
  31. %@3b_type%choice /c 1234567%@3b_nul%
  32. if %errorlevel%==1 set @3b_type=echo 1^|&goto @3b_start_1
  33. if %errorlevel%==2 set @3b_type=echo 2^|&goto @3b_start_2
  34. if %errorlevel%==3 set @3b_type=echo 3^|&goto @3b_start_3
  35. if %errorlevel%==4 set @3b_type=echo 4^|&goto @3b_start_4
  36. if %errorlevel%==5 set @3b_type=echo 5^|&goto @3b_start_5
  37. if %errorlevel%==6 set @3b_type=echo 6^|&goto @3b_start_6
  38. if %errorlevel%==7 set @3b_type=echo 7^|&goto @3b_start_7
  39.  
  40. echo エラー
  41. goto @3b_restart
  42.  
  43. :@3b_start_1
  44. goto @3b_numbers
  45.  
  46. :@3b_start_2
  47. goto @3b_alphabet_k
  48.  
  49. :@3b_start_3
  50. goto @3b_alphabet_o
  51.  
  52. :@3b_start_4
  53. set /a @3b_start_test=%random%*2/32767
  54. if %@3b_start_test%==0 goto @3b_alphabet_k
  55. if %@3b_start_test%==1 goto @3b_alphabet_o
  56.  
  57. :@3b_start_5
  58. set /a @3b_start_test=%random%*2/32767
  59. if %@3b_start_test%==0 goto @3b_alphabet_k
  60. if %@3b_start_test%==1 goto @3b_numbers
  61.  
  62. :@3b_start_6
  63. set /a @3b_start_test=%random%*2/32767
  64. if %@3b_start_test%==0 goto @3b_alphabet_o
  65. if %@3b_start_test%==1 goto @3b_numbers
  66.  
  67. :@3b_start_7
  68. set /a @3b_start_test=%random%*3/32767
  69. if %@3b_start_test%==0 goto @3b_alphabet_k
  70. if %@3b_start_test%==1 goto @3b_alphabet_o
  71. if %@3b_start_test%==2 goto @3b_numbers
  72.  
  73. rem -------------------------
  74.  
  75. :@3b_alphabet_k
  76. set /a @3b_alphabet_k=%random%*27/32767
  77.  
  78. if %@3b_alphabet_k%==1 set @3b__output_=a
  79. if %@3b_alphabet_k%==2 set @3b__output_=b
  80. if %@3b_alphabet_k%==3 set @3b__output_=c
  81. if %@3b_alphabet_k%==4 set @3b__output_=d
  82. if %@3b_alphabet_k%==5 set @3b__output_=e
  83. if %@3b_alphabet_k%==6 set @3b__output_=f
  84. if %@3b_alphabet_k%==7 set @3b__output_=g
  85. if %@3b_alphabet_k%==8 set @3b__output_=h
  86. if %@3b_alphabet_k%==9 set @3b__output_=i
  87. if %@3b_alphabet_k%==10 set @3b__output_=l
  88. if %@3b_alphabet_k%==11 set @3b__output_=k
  89. if %@3b_alphabet_k%==12 set @3b__output_=l
  90. if %@3b_alphabet_k%==13 set @3b__output_=m
  91. if %@3b_alphabet_k%==14 set @3b__output_=n
  92. if %@3b_alphabet_k%==15 set @3b__output_=o
  93. if %@3b_alphabet_k%==16 set @3b__output_=p
  94. if %@3b_alphabet_k%==17 set @3b__output_=q
  95. if %@3b_alphabet_k%==18 set @3b__output_=r
  96. if %@3b_alphabet_k%==19 set @3b__output_=s
  97. if %@3b_alphabet_k%==20 set @3b__output_=t
  98. if %@3b_alphabet_k%==21 set @3b__output_=u
  99. if %@3b_alphabet_k%==22 set @3b__output_=v
  100. if %@3b_alphabet_k%==23 set @3b__output_=w
  101. if %@3b_alphabet_k%==24 set @3b__output_=x
  102. if %@3b_alphabet_k%==25 set @3b__output_=y
  103. if %@3b_alphabet_k%==26 set @3b__output_=z
  104.  
  105. if %@3b_alphabet_k%==0 goto @3b_alphabet_k
  106. goto @3b_set
  107.  
  108. :@3b_alphabet_o
  109. set /a @3b_alphabet_o=%random%*27/32767
  110.  
  111. if %@3b_alphabet_o%==1 set @3b__output_=A
  112. if %@3b_alphabet_o%==2 set @3b__output_=B
  113. if %@3b_alphabet_o%==3 set @3b__output_=C
  114. if %@3b_alphabet_o%==4 set @3b__output_=D
  115. if %@3b_alphabet_o%==5 set @3b__output_=E
  116. if %@3b_alphabet_o%==6 set @3b__output_=F
  117. if %@3b_alphabet_o%==7 set @3b__output_=G
  118. if %@3b_alphabet_o%==8 set @3b__output_=H
  119. if %@3b_alphabet_o%==9 set @3b__output_=I
  120. if %@3b_alphabet_o%==10 set @3b__output_=J
  121. if %@3b_alphabet_o%==11 set @3b__output_=K
  122. if %@3b_alphabet_o%==12 set @3b__output_=L
  123. if %@3b_alphabet_o%==13 set @3b__output_=M
  124. if %@3b_alphabet_o%==14 set @3b__output_=N
  125. if %@3b_alphabet_o%==15 set @3b__output_=O
  126. if %@3b_alphabet_o%==16 set @3b__output_=P
  127. if %@3b_alphabet_o%==17 set @3b__output_=Q
  128. if %@3b_alphabet_o%==18 set @3b__output_=R
  129. if %@3b_alphabet_o%==19 set @3b__output_=S
  130. if %@3b_alphabet_o%==20 set @3b__output_=T
  131. if %@3b_alphabet_o%==21 set @3b__output_=U
  132. if %@3b_alphabet_o%==22 set @3b__output_=V
  133. if %@3b_alphabet_o%==23 set @3b__output_=W
  134. if %@3b_alphabet_o%==24 set @3b__output_=X
  135. if %@3b_alphabet_o%==25 set @3b__output_=Y
  136. if %@3b_alphabet_o%==26 set @3b__output_=Z
  137.  
  138. if %@3b_alphabet_o%==0 goto @3b_alphabet_o
  139. goto @3b_set
  140.  
  141. :@3b_numbers
  142. set /a @3b_numbers=%random%*10/32767
  143. set @3b__output_=%@3b_numbers%
  144. goto @3b_set
  145.  
  146. :@3b_set
  147. set @3b_nul=^>nul
  148. set @3b_output=%@3b_output%%@3b__output_%
  149. if %@3b_loop%==%@3b_u_loop% goto @3b_end
  150. set /a @3b_loop=%@3b_loop%+1
  151. goto @3b_restart
  152.  
  153. :@3b_end
  154. echo.
  155. echo ^<出力^>
  156. echo%@3b_output%
  157. echo.
  158.  
  159. choice /m 乱数をコピーしますか?
  160. if %errorlevel%==1 echo%@3b_output%|clip
  161. echo 何かキーを押して続行
  162. pause >nul
  163. goto @3b_start
  164.  
  165.  
  166.  
  167. -------------------------Javascript(HTML)-------------------------
  168. <!DOCTYPE html>
  169. <html>
  170. <head>
  171. <title>Random String Generator</title>
  172. </head>
  173. <body>
  174. <script>
  175. function getRandomNumber(max) {
  176. return Math.floor(Math.random() * max);
  177. }
  178.  
  179. function generateRandomString(length, type) {
  180. let output = '';
  181. const alphabetLower = 'abcdefghijklmnopqrstuvwxyz';
  182. const alphabetUpper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  183. const numbers = '0123456789';
  184.  
  185. for (let i = 0; i < length; i++) {
  186. let randomIndex;
  187.  
  188. switch (type) {
  189. case 1:
  190. randomIndex = getRandomNumber(numbers.length);
  191. output += numbers[randomIndex];
  192. break;
  193. case 2:
  194. randomIndex = getRandomNumber(alphabetLower.length);
  195. output += alphabetLower[randomIndex];
  196. break;
  197. case 3:
  198. randomIndex = getRandomNumber(alphabetUpper.length);
  199. output += alphabetUpper[randomIndex];
  200. break;
  201. case 4:
  202. randomIndex = getRandomNumber(2);
  203. if (randomIndex === 0) {
  204. randomIndex = getRandomNumber(alphabetLower.length);
  205. output += alphabetLower[randomIndex];
  206. } else {
  207. randomIndex = getRandomNumber(alphabetUpper.length);
  208. output += alphabetUpper[randomIndex];
  209. }
  210. break;
  211. case 5:
  212. randomIndex = getRandomNumber(2);
  213. if (randomIndex === 0) {
  214. randomIndex = getRandomNumber(numbers.length);
  215. output += numbers[randomIndex];
  216. } else {
  217. randomIndex = getRandomNumber(alphabetLower.length);
  218. output += alphabetLower[randomIndex];
  219. }
  220. break;
  221. case 6:
  222. randomIndex = getRandomNumber(2);
  223. if (randomIndex === 0) {
  224. randomIndex = getRandomNumber(numbers.length);
  225. output += numbers[randomIndex];
  226. } else {
  227. randomIndex = getRandomNumber(alphabetUpper.length);
  228. output += alphabetUpper[randomIndex];
  229. }
  230. break;
  231. case 7:
  232. randomIndex = getRandomNumber(3);
  233. if (randomIndex === 0) {
  234. randomIndex = getRandomNumber(alphabetLower.length);
  235. output += alphabetLower[randomIndex];
  236. } else if (randomIndex === 1) {
  237. randomIndex = getRandomNumber(alphabetUpper.length);
  238. output += alphabetUpper[randomIndex];
  239. } else {
  240. randomIndex = getRandomNumber(numbers.length);
  241. output += numbers[randomIndex];
  242. }
  243. break;
  244. }
  245. }
  246.  
  247. return output;
  248. }
  249.  
  250. function copyToClipboard(text) {
  251. const el = document.createElement('textarea');
  252. el.value = text;
  253. document.body.appendChild(el);
  254. el.select();
  255. document.execCommand('copy');
  256. document.body.removeChild(el);
  257. }
  258.  
  259. function main() {
  260. while (true) {
  261. const uLoop = parseInt(prompt('文字数を入力してください:'));
  262.  
  263. if (isNaN(uLoop)) {
  264. alert('無効な入力です。');
  265. continue;
  266. }
  267.  
  268. let type;
  269. while (true) {
  270. const choice = parseInt(prompt(
  271. '1. 数字\n' +
  272. '2. アルファベット小文字\n' +
  273. '3. アルファベット大文字\n' +
  274. '4. アルファベット小文字+アルファベット大文字\n' +
  275. '5. 数字+アルファベット小文字\n' +
  276. '6. 数字+アルファベット大文字\n' +
  277. '7. 数字+アルファベット小文字+アルファベット大文字\n' +
  278. 'タイプを選択してください:'
  279. ));
  280.  
  281. if (choice >= 1 && choice <= 7) {
  282. type = choice;
  283. break;
  284. }
  285.  
  286. alert('無効な入力です。');
  287. }
  288.  
  289. let output = generateRandomString(uLoop, type);
  290. alert(`\n<出力>\n${output}\n`);
  291.  
  292. const confirm = confirm('乱数をクリップボードにコピーしますか?');
  293. if (confirm) {
  294. copyToClipboard(output);
  295. }
  296.  
  297. if (!confirm('続行しますか?')) {
  298. break;
  299. }
  300. }
  301. }
  302.  
  303. main();
  304. </script>
  305. </body>
  306. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement