buelfhood/SOCO_TRAIN_java
Viewer • Updated • 76.5k • 34
How to use buelfhood/SOCO-Java-CodeBERTa-MNRL-Triplets with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("buelfhood/SOCO-Java-CodeBERTa-MNRL-Triplets")
sentences = [
"\n\nimport java.net.*;\nimport java.io.*;\n\npublic class sendMail {\n\npublic void sendMail(String mailServer, String recipient, String result) {\n try {\n Socket s = new Socket(mailServer, 25);\n BufferedReader in = new BufferedReader\n (new InputStreamReader(s.getInputStream(), \"8859_1\"));\n BufferedWriter out = new BufferedWriter\n (new OutputStreamWriter(s.getOutputStream(), \"8859_1\"));\n\n send(in, out, \"HELO client\");\n\n send(in, out, \"MAIL FROM: <WatchDog@SecureECommerce.>\");\n send(in, out, \"RCPT : \" + recipient);\n send(in, out, \"DATA\");\n send(out, \"Subject: \");\n send(out, \"From: Admin <WatchDog@SecureECommerce.>\");\n send (out, \"\\n\");\n \n send(out, result);\n send(out, \"\\n.\\n\");\n send(in, out, \"QUIT\");\n\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedReader in, BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n s = in.readLine();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}",
"import java.net.*;\nimport java.io.*;\nimport java.*;\n\n public class BruteForce {\n\n URLConnection conn = null;\n private static boolean status = false;\n\n public static void main (String args[]){\n BruteForce a = new BruteForce();\n String[] inp = {\"http://sec-crack.cs.rmit.edu./SEC/2/index.php\",\n \t\t\t\t \"\",\n \t\t\t\t \"\"};\n int attempts = 0;\n exit:\n for (int i=0;i<pwdArray.length;i++) {\n\t\t for (int j=0;j<pwdArray.length;j++) {\n\t\t\t for (int k=0;k<pwdArray.length;k++) {\n\t\t\t\t if (pwdArray[i] == ' ' && pwdArray[j] != ' ') continue;\n\t\t\t\t if (pwdArray[j] == ' ' && pwdArray[k] != ' ') continue;\n\t\t\t\t inp[2] = inp[2] + pwdArray[i] + pwdArray[j] + pwdArray[k];\n\t\t\t\t attempts++;\n \t\t\t a.doit(inp);\n \n \t\t\t\t if (status) {\n\t\t\t\t\t System.out.println(\"Crrect password is: \" + inp[2]);\n\t\t\t\t\t System.out.println(\"Number of attempts = \" + attempts);\n\t\t\t\t\t break exit;\n\t\t\t \t }\n \t\t\t inp[2] = \"\";\n\t\t \t }\n\t \t }\n }\n }\n\n public void doit(String args[]) {\n \n try {\n BufferedReader in = new BufferedReader(\n new InputStreamReader\n (connectURL(new URL(args[0]), args[1], args[2])));\n String line;\n while ((line = in.readLine()) != null) {\n System.out.println(line);\n status = true;\n }\n }\n catch (IOException e) {\n \n }\n }\n\n public InputStream connectURL (URL url, String uname, String pword)\n throws IOException {\n conn = url.openConnection();\n conn.setRequestProperty (\"Authorization\",\n userNamePasswordBase64(uname,pword));\n conn.connect ();\n return conn.getInputStream();\n }\n\n public String userNamePasswordBase64(String username, String password) {\n return \" \" + base64Encode (username + \":\" + password);\n }\n\n private final static char pwdArray [] = {\n\t 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',\n\t 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',\n\t 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',\n\t 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',\n\t 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',\n\t 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',\n\t 'W', 'X', 'Y', 'Z', ' '\n };\n\n private final static char base64Array [] = {\n 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',\n 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',\n 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',\n 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',\n 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',\n 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',\n 'w', 'x', 'y', 'z', '0', '1', '2', '3',\n '4', '5', '6', '7', '8', '9', '+', '/'\n };\n\n private static String base64Encode (String string) {\n String encodedString = \"\";\n byte bytes [] = string.getBytes ();\n int i = 0;\n int pad = 0;\n while (i < bytes.length) {\n byte b1 = bytes [i++];\n byte b2;\n byte b3;\n if (i >= bytes.length) {\n b2 = 0;\n b3 = 0;\n pad = 2;\n }\n else {\n b2 = bytes [i++];\n if (i >= bytes.length) {\n b3 = 0;\n pad = 1;\n }\n else\n b3 = bytes [i++];\n }\n byte c1 = (byte)(b1 >> 2);\n byte c2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4));\n byte c3 = (byte)(((b2 & 0xf) << 2) | (b3 >> 6));\n byte c4 = (byte)(b3 & 0x3f);\n encodedString += base64Array [c1];\n encodedString += base64Array [c2];\n switch (pad) {\n case 0:\n encodedString += base64Array [c3];\n encodedString += base64Array [c4];\n break;\n case 1:\n encodedString += base64Array [c3];\n encodedString += \"=\";\n break;\n case 2:\n encodedString += \"==\";\n break;\n }\n }\n return encodedString;\n }\n }\n\n",
"\nimport java.io.*;\n\npublic class PasswordFile {\n \n private String strFilepath;\n private String strCurrWord;\n private File fWordFile;\n private BufferedReader in;\n \n \n public PasswordFile(String filepath) {\n strFilepath = filepath;\n try {\n fWordFile = new File(strFilepath);\n in = new BufferedReader(new FileReader(fWordFile));\n }\n catch(Exception e)\n {\n System.out.println(\"Could not open file \" + strFilepath);\n }\n }\n \n String getPassword() {\n return strCurrWord;\n }\n \n String getNextPassword() {\n try {\n strCurrWord = in.readLine();\n \n \n \n }\n catch (Exception e)\n {\n \n return null;\n }\n \n return strCurrWord;\n }\n \n}\n",
"\n\nimport java.net.*;\nimport java.io.*;\n\npublic class SendEMail {\n\n public void SendEMail(){}\n\npublic void sendMail(String recipient,String c, String subject){\n try {\n\n Socket s = new Socket(\"yallara.cs.rmit.edu.\", 25);\n BufferedReader in = new BufferedReader\n (new InputStreamReader(s.getInputStream(), \"8859_1\"));\n BufferedWriter out = new BufferedWriter\n (new OutputStreamWriter(s.getOutputStream(), \"8859_1\"));\n\n send(in, out, \"HELO theWorld\");\n \n \n send(in, out, \"MAIL FROM: <watch@dog.>\");\n send(in, out, \"RCPT : \"+recipient);\n send(in, out, \"DATA\");\n send(out, \"Subject: \"+ subject);\n send(out, \"From: WatchDog.java\");\n send (out, \"\\n\");\n \n BufferedReader reader;\n String line;\n reader = new BufferedReader(new InputStreamReader(new FileInputStream()));\n line = reader.readLine();\n while (line != null){\n send(out, line);\n line = reader.readLine();\n }\n send(out, \"\\n.\\n\");\n send(in, out, \"QUIT\");\n s.print();\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedReader in, BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n s = in.readLine();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from huggingface/CodeBERTa-small-v1 on the soco_train_java dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: RobertaModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("buelfhood/SOCO-Java-CodeBERTa-MNRL-Triplets")
# Run inference
sentences = [
'import java.net.*;\nimport java.io.*;\n\npublic class BruteForce {\n private String strUserName;\n private String strURL;\n private int iAttempts;\n \n public BruteForce(String strURL,String strUserName) {\n this.strURL = strURL;\n this.strUserName = strUserName;\n this.iAttempts = 0 ;\n\n }\n \n public String getPassword(){\n URL u;\n String result ="";\n PassGenBrute PG = new PassGenBrute(3);\n URLConnection uc;\n String strPassword = new String();\n String strEncode;\n try{\n while (result.compareTo("HTTP/1.1 200 OK")!=0){\n \n strEncode = PG.getNewPassword();\n u = new URL(strURL);\n uc = u.openConnection();\n uc.setDoInput(true);\n uc.setDoOutput(true);\n strPassword = strEncode;\n strEncode = strUserName + ":" + strEncode;\n \n strEncode = new String(Base64.encode(strEncode.getBytes()));\n uc.setRequestProperty("Authorization"," " + strEncode);\n \n result = uc.getHeaderField(0);\n uc = null;\n u = null;\n iAttempts++;\n }\n\n }\n catch (Exception me) {\n System.out.println("MalformedURLException: "+me);\n }\n return(strPassword);\n }\n \n public int getAttempts(){\n return (iAttempts);\n };\n \n public static void main (String arg[]){\n timeStart = 0;\n timeEnd = 0;\n \n if (arg.length == 2) {\n BruteForce BF = new BruteForce(arg[0],arg[1]);\n System.out.println("Processing ... ");\n timeStart = System.currentTimeMillis();\n \n System.out.println("Password = " + BF.getPassword());\n timeEnd = System.currentTimeMillis();\n System.out.println("Total Time Taken = " + (timeEnd - timeStart) + " (msec)");\n System.out.println("Total Attempts = " + BF.getAttempts());\n }\n else {\n System.out.println("[Usage] java BruteForce <URL> <USERNAME>");\n\n }\n\n }\n}\n\nclass PassGenBrute {\n private char[] password;\n public PassGenBrute(int lenght) {\n password = new char[lenght];\n for (int i = 0; i < lenght; i++){\n password[i] = 65;\n }\n password[0]--;\n }\n \n public String getNewPassword()\n throws PasswordFailureException{\n password[0]++;\n\n try {\n for (int i=0; i<password.length ; i++){\n if (password[i] == 90) {\n password[i] = 97;\n }\n if (password[i] > 122) {\n password[i] = 65;\n password[i+1]++;\n }\n }\n }\n catch (RuntimeException re){\n throw new PasswordFailureException ();\n }\n return new String(password);\n }\n}\n\nclass PasswordFailureException extends RuntimeException {\n\n public PasswordFailureException() {\n }\n}',
'import java.net.*;\nimport java.io.*;\n\n\npublic class Dictionary {\n private String strUserName;\n private String strURL;\n private String strDictPath;\n private int iAttempts;\n\n \n public Dictionary(String strURL,String strUserName,String strDictPath) {\n this.strURL = strURL;\n this.strUserName = strUserName;\n this.iAttempts = 0 ;\n this.strDictPath = strDictPath;\n }\n \n\n public String getPassword(){\n URL u;\n String result ="";\n PassGenDict PG = new PassGenDict(3,strDictPath);\n URLConnection uc;\n String strPassword = new String();\n String strEncode;\n try{\n while (result.compareTo("HTTP/1.1 200 OK")!=0){\n \n strEncode = PG.getNewPassword();\n u = new URL(strURL);\n uc = u.openConnection();\n uc.setDoInput(true);\n uc.setDoOutput(true);\n strPassword = strEncode;\n strEncode = strUserName + ":" + strEncode;\n \n strEncode = new String(Base64.encode(strEncode.getBytes()));\n uc.setRequestProperty("Authorization"," " + strEncode);\n \n result = uc.getHeaderField(0);\n uc = null;\n u = null;\n iAttempts++;\n }\n\n }\n catch (Exception me) {\n System.out.println("MalformedURLException: "+me);\n }\n return(strPassword);\n }\n \n public int getAttempts(){\n return (iAttempts);\n };\n \n public static void main(String arg[]){\n timeStart = 0;\n timeEnd = 0;\n \n if (arg.length == 3) {\n Dictionary BF = new Dictionary(arg[0],arg[1],arg[2]);\n\n System.out.println("Processing ... ");\n timeStart = System.currentTimeMillis();\n System.out.println("Password = " + BF.getPassword());\n timeEnd = System.currentTimeMillis();\n System.out.println("Total Time Taken = " + (timeEnd - timeStart) + " (msec)");\n System.out.println("Total Attempts = " + BF.getAttempts());\n }\n else {\n System.out.println("[Usage] java BruteForce <URL> <USERNAME> <Dictionary path>");\n\n }\n\n }\n}\n\n\nclass PassGenDict {\n\n private char[] password;\n private String line;\n int iPassLenght;\n private BufferedReader inputFile;\n public PassGenDict(int lenght, String strDictPath) {\n try{\n inputFile = new BufferedReader(new FileReader(strDictPath));\n }\n catch (Exception e){\n }\n iPassLenght = lenght;\n }\n \n public String getNewPassword()\n throws PasswordFailureException{\n try {\n {\n line = inputFile.readLine();\n }while (line.length() != iPassLenght);\n\n }\n catch (Exception e){\n throw new PasswordFailureException ();\n }\n return (line);\n }\n}\n\nclass PasswordFailureException extends RuntimeException {\n\n public PasswordFailureException() {\n }\n}',
'import java.util.*;\nimport java.io.*;\nimport javax.swing.text.html.*;\n\n\npublic class WatchDog {\n\n public WatchDog() {\n\n }\n public static void main (String args[]) {\n DataInputStream newin;\n\n try{\n System.out.println("ishti");\n\n System.out.println("Downloading first copy");\n Runtime.getRuntime().exec("wget http://www.cs.rmit.edu./students/ -O oldfile.html");\n String[] cmdDiff = {"//sh", "-c", "diff oldfile.html newfile.html > Diff.txt"};\n String[] cmdMail = {"//sh", "-c", "mailx -s \\"Diffrence\\" \\"@cs.rmit.edu.\\" < Diff.txt"};\n while(true){\n Thread.sleep(24*60*60*1000);\n System.out.println("Downloading new copy");\n Runtime.getRuntime().exec("wget http://www.cs.rmit.edu./students/ -O newfile.html");\n Thread.sleep(2000);\n Runtime.getRuntime().exec(cmdDiff);\n Thread.sleep(2000);\n newin = new DataInputStream( new FileInputStream( "Diff.txt"));\n if (newin.readLine() != null){\n System.out.println("Sending Mail");\n Runtime.getRuntime().exec(cmdMail);\n Runtime.getRuntime().exec("cp newfile.html oldfile.html");\n\n }\n }\n\n }\n catch(Exception e){\n e.printStackTrace();\n }\n\n }\n\n}',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
anchor_code, positive_code, and negative_code| anchor_code | positive_code | negative_code | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor_code | positive_code | negative_code |
|---|---|---|
|
|
|
|
|
|
|
|
|
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
anchor_code, positive_code, and negative_code| anchor_code | positive_code | negative_code | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor_code | positive_code | negative_code |
|---|---|---|
|
|
import java.net.; |
|
|
|
import java.io.; |
import java.io.; |
|
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 1warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.0414 | 100 | 0.9269 | 0.3356 |
| 0.0827 | 200 | 0.3858 | 0.3603 |
| 0.1241 | 300 | 0.3759 | 0.3187 |
| 0.1655 | 400 | 0.3333 | 0.3243 |
| 0.2069 | 500 | 0.3541 | 0.3245 |
| 0.2482 | 600 | 0.3642 | 0.2986 |
| 0.2896 | 700 | 0.3402 | 0.3425 |
| 0.3310 | 800 | 0.3569 | 0.2971 |
| 0.3724 | 900 | 0.3429 | 0.2883 |
| 0.4137 | 1000 | 0.3484 | 0.3116 |
| 0.4551 | 1100 | 0.3331 | 0.2919 |
| 0.4965 | 1200 | 0.3277 | 0.2827 |
| 0.5379 | 1300 | 0.3195 | 0.2919 |
| 0.5792 | 1400 | 0.327 | 0.2784 |
| 0.6206 | 1500 | 0.3207 | 0.2833 |
| 0.6620 | 1600 | 0.3173 | 0.2691 |
| 0.7034 | 1700 | 0.3036 | 0.2782 |
| 0.7447 | 1800 | 0.3229 | 0.2727 |
| 0.7861 | 1900 | 0.3025 | 0.2742 |
| 0.8275 | 2000 | 0.2927 | 0.2735 |
| 0.8688 | 2100 | 0.2983 | 0.2792 |
| 0.9102 | 2200 | 0.2914 | 0.2677 |
| 0.9516 | 2300 | 0.2767 | 0.2671 |
| 0.9930 | 2400 | 0.3406 | 0.2614 |
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
@misc{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Base model
huggingface/CodeBERTa-small-v1
from sentence_transformers import SentenceTransformer model = SentenceTransformer("buelfhood/SOCO-Java-CodeBERTa-MNRL-Triplets") sentences = [ "\n\nimport java.net.*;\nimport java.io.*;\n\npublic class sendMail {\n\npublic void sendMail(String mailServer, String recipient, String result) {\n try {\n Socket s = new Socket(mailServer, 25);\n BufferedReader in = new BufferedReader\n (new InputStreamReader(s.getInputStream(), \"8859_1\"));\n BufferedWriter out = new BufferedWriter\n (new OutputStreamWriter(s.getOutputStream(), \"8859_1\"));\n\n send(in, out, \"HELO client\");\n\n send(in, out, \"MAIL FROM: <WatchDog@SecureECommerce.>\");\n send(in, out, \"RCPT : \" + recipient);\n send(in, out, \"DATA\");\n send(out, \"Subject: \");\n send(out, \"From: Admin <WatchDog@SecureECommerce.>\");\n send (out, \"\\n\");\n \n send(out, result);\n send(out, \"\\n.\\n\");\n send(in, out, \"QUIT\");\n\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedReader in, BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n s = in.readLine();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}", "import java.net.*;\nimport java.io.*;\nimport java.*;\n\n public class BruteForce {\n\n URLConnection conn = null;\n private static boolean status = false;\n\n public static void main (String args[]){\n BruteForce a = new BruteForce();\n String[] inp = {\"http://sec-crack.cs.rmit.edu./SEC/2/index.php\",\n \t\t\t\t \"\",\n \t\t\t\t \"\"};\n int attempts = 0;\n exit:\n for (int i=0;i<pwdArray.length;i++) {\n\t\t for (int j=0;j<pwdArray.length;j++) {\n\t\t\t for (int k=0;k<pwdArray.length;k++) {\n\t\t\t\t if (pwdArray[i] == ' ' && pwdArray[j] != ' ') continue;\n\t\t\t\t if (pwdArray[j] == ' ' && pwdArray[k] != ' ') continue;\n\t\t\t\t inp[2] = inp[2] + pwdArray[i] + pwdArray[j] + pwdArray[k];\n\t\t\t\t attempts++;\n \t\t\t a.doit(inp);\n \n \t\t\t\t if (status) {\n\t\t\t\t\t System.out.println(\"Crrect password is: \" + inp[2]);\n\t\t\t\t\t System.out.println(\"Number of attempts = \" + attempts);\n\t\t\t\t\t break exit;\n\t\t\t \t }\n \t\t\t inp[2] = \"\";\n\t\t \t }\n\t \t }\n }\n }\n\n public void doit(String args[]) {\n \n try {\n BufferedReader in = new BufferedReader(\n new InputStreamReader\n (connectURL(new URL(args[0]), args[1], args[2])));\n String line;\n while ((line = in.readLine()) != null) {\n System.out.println(line);\n status = true;\n }\n }\n catch (IOException e) {\n \n }\n }\n\n public InputStream connectURL (URL url, String uname, String pword)\n throws IOException {\n conn = url.openConnection();\n conn.setRequestProperty (\"Authorization\",\n userNamePasswordBase64(uname,pword));\n conn.connect ();\n return conn.getInputStream();\n }\n\n public String userNamePasswordBase64(String username, String password) {\n return \" \" + base64Encode (username + \":\" + password);\n }\n\n private final static char pwdArray [] = {\n\t 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',\n\t 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',\n\t 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',\n\t 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',\n\t 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',\n\t 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',\n\t 'W', 'X', 'Y', 'Z', ' '\n };\n\n private final static char base64Array [] = {\n 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',\n 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',\n 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',\n 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',\n 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',\n 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',\n 'w', 'x', 'y', 'z', '0', '1', '2', '3',\n '4', '5', '6', '7', '8', '9', '+', '/'\n };\n\n private static String base64Encode (String string) {\n String encodedString = \"\";\n byte bytes [] = string.getBytes ();\n int i = 0;\n int pad = 0;\n while (i < bytes.length) {\n byte b1 = bytes [i++];\n byte b2;\n byte b3;\n if (i >= bytes.length) {\n b2 = 0;\n b3 = 0;\n pad = 2;\n }\n else {\n b2 = bytes [i++];\n if (i >= bytes.length) {\n b3 = 0;\n pad = 1;\n }\n else\n b3 = bytes [i++];\n }\n byte c1 = (byte)(b1 >> 2);\n byte c2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4));\n byte c3 = (byte)(((b2 & 0xf) << 2) | (b3 >> 6));\n byte c4 = (byte)(b3 & 0x3f);\n encodedString += base64Array [c1];\n encodedString += base64Array [c2];\n switch (pad) {\n case 0:\n encodedString += base64Array [c3];\n encodedString += base64Array [c4];\n break;\n case 1:\n encodedString += base64Array [c3];\n encodedString += \"=\";\n break;\n case 2:\n encodedString += \"==\";\n break;\n }\n }\n return encodedString;\n }\n }\n\n", "\nimport java.io.*;\n\npublic class PasswordFile {\n \n private String strFilepath;\n private String strCurrWord;\n private File fWordFile;\n private BufferedReader in;\n \n \n public PasswordFile(String filepath) {\n strFilepath = filepath;\n try {\n fWordFile = new File(strFilepath);\n in = new BufferedReader(new FileReader(fWordFile));\n }\n catch(Exception e)\n {\n System.out.println(\"Could not open file \" + strFilepath);\n }\n }\n \n String getPassword() {\n return strCurrWord;\n }\n \n String getNextPassword() {\n try {\n strCurrWord = in.readLine();\n \n \n \n }\n catch (Exception e)\n {\n \n return null;\n }\n \n return strCurrWord;\n }\n \n}\n", "\n\nimport java.net.*;\nimport java.io.*;\n\npublic class SendEMail {\n\n public void SendEMail(){}\n\npublic void sendMail(String recipient,String c, String subject){\n try {\n\n Socket s = new Socket(\"yallara.cs.rmit.edu.\", 25);\n BufferedReader in = new BufferedReader\n (new InputStreamReader(s.getInputStream(), \"8859_1\"));\n BufferedWriter out = new BufferedWriter\n (new OutputStreamWriter(s.getOutputStream(), \"8859_1\"));\n\n send(in, out, \"HELO theWorld\");\n \n \n send(in, out, \"MAIL FROM: <watch@dog.>\");\n send(in, out, \"RCPT : \"+recipient);\n send(in, out, \"DATA\");\n send(out, \"Subject: \"+ subject);\n send(out, \"From: WatchDog.java\");\n send (out, \"\\n\");\n \n BufferedReader reader;\n String line;\n reader = new BufferedReader(new InputStreamReader(new FileInputStream()));\n line = reader.readLine();\n while (line != null){\n send(out, line);\n line = reader.readLine();\n }\n send(out, \"\\n.\\n\");\n send(in, out, \"QUIT\");\n s.print();\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedReader in, BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n s = in.readLine();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4]